File tree 3 files changed +32
-15
lines changed
3 files changed +32
-15
lines changed Original file line number Diff line number Diff line change @@ -1735,10 +1735,14 @@ def _list_cases(suite):
1735
1735
if isinstance (test , unittest .TestSuite ):
1736
1736
_list_cases (test )
1737
1737
elif isinstance (test , unittest .TestCase ):
1738
- print (test .id ())
1738
+ if support ._match_test (test ):
1739
+ print (test .id ())
1739
1740
1740
1741
1741
1742
def list_cases (ns , selected ):
1743
+ support .verbose = False
1744
+ support .match_tests = ns .match_tests
1745
+
1742
1746
skipped = []
1743
1747
for test in selected :
1744
1748
abstest = get_abs_module (ns , test )
Original file line number Diff line number Diff line change @@ -1866,6 +1866,23 @@ def _run_suite(suite):
1866
1866
raise TestFailed (err )
1867
1867
1868
1868
1869
+ def _match_test (test ):
1870
+ global match_tests
1871
+
1872
+ if match_tests is None :
1873
+ return True
1874
+ test_id = test .id ()
1875
+
1876
+ for match_test in match_tests :
1877
+ if fnmatch .fnmatchcase (test_id , match_test ):
1878
+ return True
1879
+
1880
+ for name in test_id .split ("." ):
1881
+ if fnmatch .fnmatchcase (name , match_test ):
1882
+ return True
1883
+ return False
1884
+
1885
+
1869
1886
def run_unittest (* classes ):
1870
1887
"""Run tests from unittest.TestCase-derived classes."""
1871
1888
valid_types = (unittest .TestSuite , unittest .TestCase )
@@ -1880,20 +1897,7 @@ def run_unittest(*classes):
1880
1897
suite .addTest (cls )
1881
1898
else :
1882
1899
suite .addTest (unittest .makeSuite (cls ))
1883
- def case_pred (test ):
1884
- if match_tests is None :
1885
- return True
1886
- test_id = test .id ()
1887
-
1888
- for match_test in match_tests :
1889
- if fnmatch .fnmatchcase (test_id , match_test ):
1890
- return True
1891
-
1892
- for name in test_id .split ("." ):
1893
- if fnmatch .fnmatchcase (name , match_test ):
1894
- return True
1895
- return False
1896
- _filter_suite (suite , case_pred )
1900
+ _filter_suite (suite , _match_test )
1897
1901
_run_suite (suite )
1898
1902
1899
1903
#=======================================================================
Original file line number Diff line number Diff line change @@ -794,11 +794,20 @@ def test_method2(self):
794
794
pass
795
795
""" )
796
796
testname = self .create_test (code = code )
797
+
798
+ # Test --list-cases
797
799
all_methods = ['%s.Tests.test_method1' % testname ,
798
800
'%s.Tests.test_method2' % testname ]
799
801
output = self .run_tests ('--list-cases' , testname )
800
802
self .assertEqual (output .splitlines (), all_methods )
801
803
804
+ # Test --list-cases with --match
805
+ all_methods = ['%s.Tests.test_method1' % testname ]
806
+ output = self .run_tests ('--list-cases' ,
807
+ '-m' , 'test_method1' ,
808
+ testname )
809
+ self .assertEqual (output .splitlines (), all_methods )
810
+
802
811
def test_crashed (self ):
803
812
# Any code which causes a crash
804
813
code = 'import faulthandler; faulthandler._sigsegv()'
You can’t perform that action at this time.
0 commit comments