summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorBenjamin Berg <bberg@redhat.com>2022-05-03 12:01:37 +0200
committerBenjamin Berg <bberg@redhat.com>2022-05-05 15:44:22 +0200
commit1fa6fb5c3050835ce968e357ba9440be72e7ef6a (patch)
tree2cd26257d7e770bb656c78908cc4c82e4593e8cb
parentae04fa989720279e5558c3b8ff9ebe1959b1cf36 (diff)
tests: Skip tests when dependencies are missingbenzea/test-skip-if-nodep
By default, just skip tests when a dependency is missing. However, for now do not allow disabling the tests and add an option to turn the skipping behaviour into an error (enabled in the CI). Closes: #133
-rw-r--r--.gitlab-ci.yml8
-rw-r--r--meson.build6
-rw-r--r--meson_options.txt5
-rw-r--r--tests/dbusmock-services/fprintd.py (renamed from tests/dbusmock/fprintd.py)0
-rw-r--r--tests/dbusmock-services/polkitd.py (renamed from tests/dbusmock/polkitd.py)0
-rw-r--r--tests/fprintd.py18
-rw-r--r--tests/meson.build2
-rw-r--r--tests/pam/test_pam_fprintd.py12
-rwxr-xr-xtests/test_fprintd_utils.py14
9 files changed, 44 insertions, 21 deletions
diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml
index 974a25f..e16ba90 100644
--- a/.gitlab-ci.yml
+++ b/.gitlab-ci.yml
@@ -67,7 +67,7 @@ build_stable:
stage: build
allow_failure: true
script:
- - meson _build
+ - meson _build -Drequire_tests=true
- ninja -C _build -v
- ninja -C _build -v install
@@ -77,7 +77,7 @@ build_dev:
- .install_libfprint_dev
stage: build
script:
- - meson _build --werror -Dgtk_doc=true
+ - meson _build -Drequire_tests=true --werror -Dgtk_doc=true
- ninja -C _build -v
- ninja -C _build -v install
artifacts:
@@ -92,7 +92,7 @@ test_dev:
- .install_libfprint_dev
stage: test
script:
- - meson _build -Db_coverage=true
+ - meson _build -Db_coverage=true -Drequire_tests=true
- meson test -C _build --print-errorlogs --no-stdsplit --timeout-multiplier 3
- ninja -C _build coverage
- cat _build/meson-logs/coverage.txt
@@ -109,7 +109,7 @@ test_dev_with_sanitizer:
- .install_libfprint_dev
stage: test
script:
- - meson _build -Db_sanitize=address
+ - meson _build -Db_sanitize=address -Drequire_tests=true
- meson test -C _build --print-errorlogs --no-stdsplit --timeout-multiplier 5
artifacts:
name: meson-logs
diff --git a/meson.build b/meson.build
index b155a4a..41bd70c 100644
--- a/meson.build
+++ b/meson.build
@@ -153,7 +153,11 @@ python3_available_modules = []
foreach module, required : python3_test_modules
if required and run_command(python3, '-c', 'import @0@'.format(module)).returncode() != 0
- error('Python3 module \'' + module + '\' required by test suite not found')
+ if not get_option('require_tests')
+ warning('Python3 module \'' + module + '\' required to run (some) tests')
+ else
+ error('Python3 module \'' + module + '\' required by test suite not found')
+ endif
endif
endforeach
diff --git a/meson_options.txt b/meson_options.txt
index 5daa9a4..10a2b5b 100644
--- a/meson_options.txt
+++ b/meson_options.txt
@@ -23,3 +23,8 @@ option('gtk_doc',
type: 'boolean',
value: false,
description: 'Use gtk-doc to build documentation')
+
+option('require_tests',
+ type: 'boolean',
+ value: false,
+ description: 'Make tests error out if a dependency is missing')
diff --git a/tests/dbusmock/fprintd.py b/tests/dbusmock-services/fprintd.py
index b4682a7..b4682a7 100644
--- a/tests/dbusmock/fprintd.py
+++ b/tests/dbusmock-services/fprintd.py
diff --git a/tests/dbusmock/polkitd.py b/tests/dbusmock-services/polkitd.py
index 3f4d078..3f4d078 100644
--- a/tests/dbusmock/polkitd.py
+++ b/tests/dbusmock-services/polkitd.py
diff --git a/tests/fprintd.py b/tests/fprintd.py
index 64ea42e..5672ca2 100644
--- a/tests/fprintd.py
+++ b/tests/fprintd.py
@@ -32,13 +32,17 @@ import re
import shutil
import socket
import struct
-import dbusmock
-import gi
-gi.require_version('FPrint', '2.0')
-from gi.repository import GLib, Gio, FPrint
-from output_checker import OutputChecker
-import cairo
import signal
+from output_checker import OutputChecker
+try:
+ import dbusmock
+ import gi
+ gi.require_version('FPrint', '2.0')
+ from gi.repository import GLib, Gio, FPrint
+ import cairo
+except Exception as e:
+ print("Missing dependencies: %s" % str(e))
+ sys.exit(1 if os.getenv('REQUIRE_TESTS') else 77)
try:
from subprocess import DEVNULL
@@ -326,7 +330,7 @@ class FPrintdTest(dbusmock.DBusTestCase):
if 'POLKITD_MOCK_PATH' in os.environ:
polkitd_template = os.path.join(os.getenv('POLKITD_MOCK_PATH'), 'polkitd.py')
else:
- polkitd_template = os.path.join(os.path.dirname(__file__), 'dbusmock/polkitd.py')
+ polkitd_template = os.path.join(os.path.dirname(__file__), 'dbusmock-services/polkitd.py')
print ('Using template from %s' % polkitd_template)
self._polkitd, self._polkitd_obj = self.spawn_server_template(
diff --git a/tests/meson.build b/tests/meson.build
index 495acbc..4b15b13 100644
--- a/tests/meson.build
+++ b/tests/meson.build
@@ -76,7 +76,7 @@ foreach pt: python_tests
suite: ut_suite,
depends: pt.get('depends', []),
workdir: pt.get('workdir', meson.build_root()),
- env: pt.get('env', []),
+ env: pt.get('env', []) + (get_option('require_tests') ? ['REQUIRE_TESTS=1'] : []),
timeout: pt.get('timeout', 30),
is_parallel: pt.get('is_parallel', true),
)
diff --git a/tests/pam/test_pam_fprintd.py b/tests/pam/test_pam_fprintd.py
index bd43497..2bddff3 100644
--- a/tests/pam/test_pam_fprintd.py
+++ b/tests/pam/test_pam_fprintd.py
@@ -15,13 +15,17 @@ import tempfile
import unittest
import sys
import subprocess
-import dbus
-import dbusmock
import glob
import os
import shutil
import time
-import pypamtest
+try:
+ import dbusmock
+ import pypamtest
+ import dbus
+except Exception as e:
+ print("Missing dependencies: %s" % str(e))
+ sys.exit(1 if os.getenv('REQUIRE_TESTS') else 77)
PAM_SUCCESS = 0
PAM_AUTH_ERR = 7
@@ -62,7 +66,7 @@ class TestPamFprintd(dbusmock.DBusTestCase):
template_path = './'
if 'TOPSRCDIR' in os.environ:
template_path = os.environ['TOPSRCDIR'] + '/tests/'
- klass.template_name = template_path + 'dbusmock/fprintd.py'
+ klass.template_name = template_path + 'dbusmock-services/fprintd.py'
print ('Using template from %s' % klass.template_name)
@classmethod
diff --git a/tests/test_fprintd_utils.py b/tests/test_fprintd_utils.py
index efa5893..8855887 100755
--- a/tests/test_fprintd_utils.py
+++ b/tests/test_fprintd_utils.py
@@ -15,13 +15,19 @@ import tempfile
import unittest
import sys
import subprocess
-import dbus
-import dbus.mainloop.glib
-import dbusmock
import os
import time
from output_checker import OutputChecker
+import os
+import time
+try:
+ import dbusmock
+ import dbus
+ import dbus.mainloop.glib
+except Exception as e:
+ print("Missing dependencies: %s" % str(e))
+ sys.exit(1 if os.getenv('REQUIRE_TESTS') else 77)
VALID_FINGER_NAMES = [
'left-thumb',
@@ -50,7 +56,7 @@ class TestFprintdUtilsBase(dbusmock.DBusTestCase):
template_path = './'
if 'TOPSRCDIR' in os.environ:
template_path = os.environ['TOPSRCDIR'] + '/tests/'
- klass.template_name = template_path + 'dbusmock/fprintd.py'
+ klass.template_name = template_path + 'dbusmock-services/fprintd.py'
print ('Using template from %s' % klass.template_name)
klass.tools_prefix = ''