From 9b580182e9213abbcf28d6682722bb1fe4e5caff Mon Sep 17 00:00:00 2001 From: Gard Spreemann Date: Fri, 10 Jul 2020 10:46:55 +0200 Subject: Leverage PyTest to simplify autopkgtests. --- debian/tests/upstream.py | 48 ++++++++++++------------------------------------ 1 file changed, 12 insertions(+), 36 deletions(-) (limited to 'debian/tests/upstream.py') diff --git a/debian/tests/upstream.py b/debian/tests/upstream.py index 869d469e..c21aff8d 100644 --- a/debian/tests/upstream.py +++ b/debian/tests/upstream.py @@ -1,42 +1,18 @@ -import importlib -import os import sys +import itertools +import pytest -blacklist = {"test_knn", "test_subsampling", "test_representations", "test_dtm"} +blacklist = ["test_dtm.py", # Requires hnswlib + "test_knn.py", # Requires pykeops + "test_representations.py", # Look into this + "test_wasserstein_distance.py::test_wasserstein_distance_pot", # Requires eagerpy. + "test_wasserstein_distance.py::test_wasserstein_distance_grad" # Requires eagerpy. + ] -testdir = sys.argv[1] -sys.path.append(testdir) - -results = [] -with os.scandir(testdir) as it: - for entry in it: - if entry.is_file() and entry.name.startswith("test_") and entry.name.endswith(".py"): - name = entry.name[:-3] +print("Blacklist: %s" %(str(blacklist))) - if name in blacklist: - print("Skipping tests in %s due to blacklist." %(name)) - else: - print("Running tests from %s." %(name)) - - module = importlib.import_module(name) +testdir = sys.argv[1] - tests = [f for f in dir(module) if str(f).startswith("test_")] - for t in tests: - func = getattr(module, t) - if callable(func): - print(" ", t) - ok = True - try: - func() - except AssertionError: - ok = False - if ok: - print(" OK!") - else: - print(" FAIL!") - results.append(ok) +deselect_args = list(itertools.chain.from_iterable([["--deselect", "%s/%s" %(testdir, exclude)] for exclude in blacklist])) -if all(results): - exit(0) -else: - exit(1) +pytest.main([testdir] + deselect_args) -- cgit v1.2.3