From 43460fae880de7e7b61e1db23bdd987fde96f7a2 Mon Sep 17 00:00:00 2001 From: crusaderky Date: Wed, 7 Sep 2022 12:04:16 +0100 Subject: [PATCH] Gracefully fail imports --- dashboard.py | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/dashboard.py b/dashboard.py index e448b63976..dfbcd5d985 100644 --- a/dashboard.py +++ b/dashboard.py @@ -38,7 +38,12 @@ def load_test_source() -> None: tests being importable from this script. """ for fname in glob.iglob("tests/**/test_*.py", recursive=True): - mod = importlib.import_module(fname.replace("/", ".")[: -len(".py")]) + try: + mod = importlib.import_module(fname.replace("/", ".")[: -len(".py")]) + # Some pytest exceptions inherit directly from BaseException + except BaseException as e: + print(f"Could not import {fname}: {e.__class__.__name__}: {e}") + continue tests = [a for a in dir(mod) if a.startswith("test_")] for test in tests: if (func := getattr(mod, test, None)) and callable(func):