aboutsummaryrefslogtreecommitdiff
path: root/test
diff options
context:
space:
mode:
authorGravatar Nikolaus Rath <Nikolaus@rath.org>2017-01-10 14:34:42 -0800
committerGravatar Nikolaus Rath <Nikolaus@rath.org>2017-01-10 14:42:26 -0800
commit5c76353fe637a8ca769d25d0b0ad1b166606e5c7 (patch)
treee91284aad519aecc31d0a9fc9f5aa91cc92ee158 /test
parent09d388570b5ad0085855d90eea9be653e4bc9723 (diff)
Skip tests if not root and no setuid fusermount3.
Diffstat (limited to 'test')
-rw-r--r--test/pytest.ini2
-rwxr-xr-xtest/test_examples.py4
-rw-r--r--test/util.py37
3 files changed, 41 insertions, 2 deletions
diff --git a/test/pytest.ini b/test/pytest.ini
index bc4af36..9516154 100644
--- a/test/pytest.ini
+++ b/test/pytest.ini
@@ -1,2 +1,2 @@
[pytest]
-addopts = --verbose --assert=rewrite --tb=native -x
+addopts = --verbose --assert=rewrite --tb=native -x -r a
diff --git a/test/test_examples.py b/test/test_examples.py
index 95eeb9a..cfd6734 100755
--- a/test/test_examples.py
+++ b/test/test_examples.py
@@ -17,11 +17,13 @@ import platform
from distutils.version import LooseVersion
from tempfile import NamedTemporaryFile
from util import (wait_for_mount, umount, cleanup, base_cmdline,
- safe_sleep, basename)
+ safe_sleep, basename, fuse_test_marker)
from os.path import join as pjoin
TEST_FILE = __file__
+pytestmark = fuse_test_marker()
+
with open(TEST_FILE, 'rb') as fh:
TEST_DATA = fh.read()
diff --git a/test/util.py b/test/util.py
index 76b8ec1..6bba9e2 100644
--- a/test/util.py
+++ b/test/util.py
@@ -2,6 +2,7 @@
import subprocess
import pytest
import os
+import stat
import time
from os.path import join as pjoin
@@ -68,6 +69,42 @@ def safe_sleep(secs):
time.sleep(end - now)
now = time.time()
+def fuse_test_marker():
+ '''Return a pytest.marker that indicates FUSE availability
+
+ If system/user/environment does not support FUSE, return
+ a `pytest.mark.skip` object with more details. If FUSE is
+ supported, return `pytest.mark.uses_fuse()`.
+ '''
+
+ skip = lambda x: pytest.mark.skip(reason=x)
+
+ with subprocess.Popen(['which', 'fusermount3'], stdout=subprocess.PIPE,
+ universal_newlines=True) as which:
+ fusermount_path = which.communicate()[0].strip()
+
+ if not fusermount_path or which.returncode != 0:
+ return skip("Can't find fusermount executable")
+
+ if not os.path.exists('/dev/fuse'):
+ return skip("FUSE kernel module does not seem to be loaded")
+
+ if os.getuid() == 0:
+ return pytest.mark.uses_fuse()
+
+ mode = os.stat(fusermount_path).st_mode
+ if mode & stat.S_ISUID == 0:
+ return skip('fusermount executable not setuid, and we are not root.')
+
+ try:
+ fd = os.open('/dev/fuse', os.O_RDWR)
+ except OSError as exc:
+ return skip('Unable to open /dev/fuse: %s' % exc.strerror)
+ else:
+ os.close(fd)
+
+ return pytest.mark.uses_fuse()
+
# If valgrind and libtool are available, use them
def has_program(name):
try: