From 29bfafa6761ad954567050c623f7f8193ec1bc5d Mon Sep 17 00:00:00 2001 From: Kovid Goyal Date: Wed, 30 Sep 2020 12:32:56 +0530 Subject: [PATCH] When finding tests also check for pyc Needed in frozen builds --- src/calibre/utils/run_tests.py | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/src/calibre/utils/run_tests.py b/src/calibre/utils/run_tests.py index c6c36c4253..3b0fd5c05b 100644 --- a/src/calibre/utils/run_tests.py +++ b/src/calibre/utils/run_tests.py @@ -57,8 +57,14 @@ def find_tests_in_package(package, excludes=('main.py',)): loader = importlib.import_module(package).__spec__.loader items = list(loader.contents()) suits = [] + excludes = set(excludes) | {x + 'c' for x in excludes} + seen = set() for x in items: - if x.endswith('.py') and x not in excludes: + if (x.endswith('.py') or x.endswith('.pyc')) and x not in excludes: + q = x.rpartition('.')[0] + if q in seen: + continue + seen.add(q) m = importlib.import_module(package + '.' + x.partition('.')[0]) suits.append(unittest.defaultTestLoader.loadTestsFromModule(m)) return unittest.TestSuite(suits)