From c8301efc5911ab5af83e567aaa6c755f8f91c681 Mon Sep 17 00:00:00 2001 From: Rob Browning Date: Sat, 4 Dec 2021 12:32:50 -0600 Subject: [PATCH] Teach pytest to handle WVSKIP and use it where we can Have pytest scan the wvtest output for skip messages, and for now, treat the whole test as skipped if we find any. This means that for now WVSKIP can only be used as an up-front guard, but that's all we need in most cases. This should help make it more likely that we'll notice when tests are unexpectedly skipped. Signed-off-by: Rob Browning Tested-by: Rob Browning --- test/ext/conftest.py | 7 ++++++- test/ext/test-fuse | 8 ++++---- test/ext/test-import-duplicity | 3 +-- test/ext/test-import-rdiff-backup | 3 +-- test/ext/test-index-check-device | 14 +++++++------- test/ext/test-meta | 2 +- test/ext/test-restore-map-owner | 4 ++-- test/ext/test-save-restore | 2 +- test/ext/test-save-strip-graft | 2 +- test/ext/test-sparse-files | 2 +- test/ext/test-web | 7 +++---- test/ext/test-xdev | 10 +++++----- 12 files changed, 33 insertions(+), 31 deletions(-) diff --git a/test/ext/conftest.py b/test/ext/conftest.py index a79d033..2c8f03e 100644 --- a/test/ext/conftest.py +++ b/test/ext/conftest.py @@ -28,7 +28,12 @@ class BupSubprocTestRunner(pytest.Item): out = p.communicate()[0] sys.stdout.flush() byte_stream(sys.stdout).write(out) - failures = [line for line in out.splitlines() + lines = out.splitlines() + for line in lines: + if line.startswith(b'!') and line.lower().endswith(b' skip ok'): + pytest.skip(line.decode('ascii')) + return + failures = [line for line in lines if (line.startswith(b'!') and line.lower().endswith(b' failed'))] if failures or p.returncode != 0: diff --git a/test/ext/test-fuse b/test/ext/test-fuse index f3ca493..bfe04a9 100755 --- a/test/ext/test-fuse +++ b/test/ext/test-fuse @@ -9,22 +9,22 @@ unset BLOCKSIZE BLOCK_SIZE DF_BLOCK_SIZE root_status="$(dev/root-status)" || exit $? if ! bup-python -c 'import fuse' 2> /dev/null; then - WVSTART 'unable to import fuse; skipping test' + WVSKIP 'unable to import fuse; skipping test' exit 0 fi if test -n "$(type -p modprobe)" && ! modprobe fuse; then - echo 'Unable to load fuse module; skipping dependent tests.' 1>&2 + WVSKIP 'Unable to load fuse module; skipping dependent tests.' exit 0 fi if ! fusermount -V; then - echo 'skipping FUSE tests: fusermount does not appear to work' + WVSKIP 'skipping FUSE tests: fusermount does not appear to work' exit 0 fi if ! groups | grep -q fuse && test "$root_status" != root; then - echo 'skipping FUSE tests: you are not root and not in the fuse group' + WVSKIP 'skipping FUSE tests: you are not root and not in the fuse group' exit 0 fi diff --git a/test/ext/test-import-duplicity b/test/ext/test-import-duplicity index 9374f9a..289793e 100755 --- a/test/ext/test-import-duplicity +++ b/test/ext/test-import-duplicity @@ -4,8 +4,7 @@ set -o pipefail if ! [ "$(type -p duplicity)" != "" ]; then - # FIXME: add WVSKIP. - echo "Cannot find duplicity; skipping test)" 1>&2 + WVSKIP 'Cannot find duplicity; skipping test)' exit 0 fi diff --git a/test/ext/test-import-rdiff-backup b/test/ext/test-import-rdiff-backup index 359f081..6e719ec 100755 --- a/test/ext/test-import-rdiff-backup +++ b/test/ext/test-import-rdiff-backup @@ -12,8 +12,7 @@ export GIT_DIR="$tmpdir/bup" bup() { "$top/bup" "$@"; } if ! [ "$(type -p rdiff-backup)" != "" ]; then - # FIXME: add WVSKIP. - echo "Cannot find rdiff-backup; skipping test)" 1>&2 + WVSKIP 'Cannot find rdiff-backup; skipping test)' exit 0 fi diff --git a/test/ext/test-index-check-device b/test/ext/test-index-check-device index a0861c7..3bba999 100755 --- a/test/ext/test-index-check-device +++ b/test/ext/test-index-check-device @@ -7,23 +7,23 @@ set -o pipefail root_status="$(dev/root-status)" || exit $? if [ "$root_status" != root ]; then - echo 'Not root: skipping --check-device tests.' - exit 0 # FIXME: add WVSKIP. + WVSKIP 'Not root: skipping --check-device tests.' + exit 0 fi if test -n "$(type -p modprobe)" && ! modprobe loop; then - echo 'Unable to load loopback module; skipping --check-device test.' 1>&2 + WVSKIP 'Unable to load loopback module; skipping --check-device test.' exit 0 fi if test -z "$(type -p losetup)"; then - echo 'Unable to find losetup: skipping --check-device tests.' 1>&2 - exit 0 # FIXME: add WVSKIP. + WVSKIP 'Unable to find losetup: skipping --check-device tests.' + exit 0 fi if test -z "$(type -p mke2fs)"; then - echo 'Unable to find mke2fs: skipping --check-device tests.' 1>&2 - exit 0 # FIXME: add WVSKIP. + WVSKIP 'Unable to find mke2fs: skipping --check-device tests.' + exit 0 fi WVSTART '--check-device' diff --git a/test/ext/test-meta b/test/ext/test-meta index a20748b..4d6b86a 100755 --- a/test/ext/test-meta +++ b/test/ext/test-meta @@ -640,7 +640,7 @@ if [ "$root_status" = root ]; then if ! modprobe loop; then echo 'Unable to load loopback module; skipping dependent tests.' 1>&2 - exit 0 + exit 0 # FIXME: allow intermixed WVSKIPs fi testfs="$(WVPASS wvmkmountpt)" || exit $? diff --git a/test/ext/test-restore-map-owner b/test/ext/test-restore-map-owner index 348ce3c..ff164da 100755 --- a/test/ext/test-restore-map-owner +++ b/test/ext/test-restore-map-owner @@ -5,8 +5,8 @@ root_status="$(dev/root-status)" || exit $? if [ "$root_status" != root ]; then - echo 'Not root: skipping restore --map-* tests.' - exit 0 # FIXME: add WVSKIP. + WVSKIP 'Not root: skipping restore --map-* tests.' + exit 0 fi top="$(WVPASS pwd)" || exit $? diff --git a/test/ext/test-save-restore b/test/ext/test-save-restore index 30ade4c..012ae68 100755 --- a/test/ext/test-save-restore +++ b/test/ext/test-save-restore @@ -131,7 +131,7 @@ WVSTART "save disjoint top-level directories" if [ "$pwd_top" = "$tmp_top" ]; then echo "(running from within /$tmp_top; skipping test)" 1>&2 - exit 0 + exit 0 # FIXME: allow intermixed WVSKIPs fi D=bupdata.tmp WVPASS force-delete $D diff --git a/test/ext/test-save-strip-graft b/test/ext/test-save-strip-graft index 78b79fe..32b954b 100755 --- a/test/ext/test-save-strip-graft +++ b/test/ext/test-save-strip-graft @@ -59,7 +59,7 @@ then # current filesystem may fail -- i.e. running from # /foo/ext4/bar/btrfs will fail when bup tries to restore linux # attrs above btrfs to the restore tree *inside* btrfs. - # FIXME: add WVSKIP + # FIXME: allow intermixed WVSKIPs echo "(running from tree with mixed filesystems; skipping test)" 1>&2 exit 0 else diff --git a/test/ext/test-sparse-files b/test/ext/test-sparse-files index c000784..d19bf18 100755 --- a/test/ext/test-sparse-files +++ b/test/ext/test-sparse-files @@ -27,7 +27,7 @@ readonly block_size data_size WVPASS dd if=/dev/zero of=test-sparse-probe seek="$data_size" bs=1 count=1 probe_size=$(WVPASS du -k -s test-sparse-probe | WVPASS cut -f1) || exit $? if [ "$probe_size" -ge "$((data_size / 1024))" ]; then - WVSTART "no sparse support detected -- skipping tests" + WVSKIP "no sparse support detected -- skipping tests" exit 0 fi diff --git a/test/ext/test-web b/test/ext/test-web index b53eb5c..7349890 100755 --- a/test/ext/test-web +++ b/test/ext/test-web @@ -27,21 +27,20 @@ wait-for-server-start() WVPASS cd "$tmpdir" -# FIXME: add WVSKIP if test -z "$(type -p curl)"; then - WVSTART 'curl does not appear to be installed; skipping test' + WVSKIP 'curl does not appear to be installed; skipping test' exit 0 fi WVPASS bup-cfg-py -c "import socket as s; s.socket(s.AF_UNIX).bind('socket')" curl -s --unix-socket ./socket http://localhost/foo if test $? -ne 7; then - WVSTART 'curl does not appear to support --unix-socket; skipping test' + WVSKIP 'curl does not appear to support --unix-socket; skipping test' exit 0 fi if ! bup-python -c 'import tornado' 2> /dev/null; then - WVSTART 'unable to import tornado; skipping test' + WVSKIP 'unable to import tornado; skipping test' exit 0 fi diff --git a/test/ext/test-xdev b/test/ext/test-xdev index 78861a9..cc5a2c0 100755 --- a/test/ext/test-xdev +++ b/test/ext/test-xdev @@ -6,20 +6,20 @@ set -o pipefail root_status="$(dev/root-status)" || exit $? if [ "$root_status" != root ]; then - WVSTART 'not root: skipping tests' - exit 0 # FIXME: add WVSKIP. + WVSKIP 'not root: skipping tests' + exit 0 fi if ! modprobe loop; then - WVSTART 'unable to load loopback module; skipping tests' 1>&2 + WVSKIP 'unable to load loopback module; skipping tests' exit 0 fi # These tests are only likely to work under Linux for now # (patches welcome). if ! [[ $(uname) =~ Linux ]]; then - WVSTART 'not Linux: skipping tests' - exit 0 # FIXME: add WVSKIP. + WVSKIP 'not Linux: skipping tests' + exit 0 fi top="$(WVPASS pwd)" || exit $? -- 2.39.2