File tree 1 file changed +9
-5
lines changed
1 file changed +9
-5
lines changed Original file line number Diff line number Diff line change @@ -34,15 +34,17 @@ def testsuite(pattern=''):
34
34
The TestSuite object containing the matching tests.
35
35
'''
36
36
import re
37
+ from os .path import dirname
37
38
from itertools import chain
38
39
from pkg_resources import resource_filename
39
40
loader = unittest .defaultTestLoader
40
41
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.
46
48
suite = unittest .TestSuite ()
47
49
rx = re .compile (pattern )
48
50
tcases = chain .from_iterable (chain .from_iterable (suite_all ))
@@ -51,6 +53,8 @@ def testsuite(pattern=''):
51
53
shortname = '.' .join (tcwords [- 2 :])
52
54
if rx .search (shortname ):
53
55
suite .addTest (tc )
56
+ # verify all tests are found for an empty pattern.
57
+ assert pattern or suite_all .countTestCases () == suite .countTestCases ()
54
58
return suite
55
59
56
60
You can’t perform that action at this time.
0 commit comments