Skip to content

Commit 6cd3bb4

Browse files
committed
TST: Use top_level_dir in test discovery.
top_level_dir affects the test case `id` which is used by codecov to match the source files.
1 parent 88f7762 commit 6cd3bb4

File tree

1 file changed

+9
-5
lines changed

1 file changed

+9
-5
lines changed

Diff for: pyobjcryst/tests/__init__.py

+9-5
Original file line numberDiff line numberDiff line change
@@ -34,15 +34,17 @@ def testsuite(pattern=''):
3434
The TestSuite object containing the matching tests.
3535
'''
3636
import re
37+
from os.path import dirname
3738
from itertools import chain
3839
from pkg_resources import resource_filename
3940
loader = unittest.defaultTestLoader
4041
thisdir = resource_filename(__name__, '')
41-
suite_all = loader.discover(thisdir)
42-
# shortcut when pattern is not specified
43-
if not pattern:
44-
return suite_all
45-
# here we need to filter the suite by pattern
42+
depth = __name__.count('.') + 1
43+
topdir = thisdir
44+
for i in range(depth):
45+
topdir = dirname(topdir)
46+
suite_all = loader.discover(thisdir, top_level_dir=topdir)
47+
# always filter the suite by pattern to test-cover the selection code.
4648
suite = unittest.TestSuite()
4749
rx = re.compile(pattern)
4850
tcases = chain.from_iterable(chain.from_iterable(suite_all))
@@ -51,6 +53,8 @@ def testsuite(pattern=''):
5153
shortname = '.'.join(tcwords[-2:])
5254
if rx.search(shortname):
5355
suite.addTest(tc)
56+
# verify all tests are found for an empty pattern.
57+
assert pattern or suite_all.countTestCases() == suite.countTestCases()
5458
return suite
5559

5660

0 commit comments

Comments
 (0)