File tree Expand file tree Collapse file tree 3 files changed +32
-15
lines changed Expand file tree Collapse file tree 3 files changed +32
-15
lines changed Original file line number Diff line number Diff line change @@ -256,9 +256,13 @@ def _list_cases(self, suite):
256256 if isinstance (test , unittest .TestSuite ):
257257 self ._list_cases (test )
258258 elif isinstance (test , unittest .TestCase ):
259- print (test .id ())
259+ if support ._match_test (test ):
260+ print (test .id ())
260261
261262 def list_cases (self ):
263+ support .verbose = False
264+ support .match_tests = self .ns .match_tests
265+
262266 for test in self .selected :
263267 abstest = get_abs_module (self .ns , test )
264268 try :
Original file line number Diff line number Diff line change @@ -1905,6 +1905,23 @@ def _run_suite(suite):
19051905 raise TestFailed (err )
19061906
19071907
1908+ def _match_test (test ):
1909+ global match_tests
1910+
1911+ if match_tests is None :
1912+ return True
1913+ test_id = test .id ()
1914+
1915+ for match_test in match_tests :
1916+ if fnmatch .fnmatchcase (test_id , match_test ):
1917+ return True
1918+
1919+ for name in test_id .split ("." ):
1920+ if fnmatch .fnmatchcase (name , match_test ):
1921+ return True
1922+ return False
1923+
1924+
19081925def run_unittest (* classes ):
19091926 """Run tests from unittest.TestCase-derived classes."""
19101927 valid_types = (unittest .TestSuite , unittest .TestCase )
@@ -1919,20 +1936,7 @@ def run_unittest(*classes):
19191936 suite .addTest (cls )
19201937 else :
19211938 suite .addTest (unittest .makeSuite (cls ))
1922- def case_pred (test ):
1923- if match_tests is None :
1924- return True
1925- test_id = test .id ()
1926-
1927- for match_test in match_tests :
1928- if fnmatch .fnmatchcase (test_id , match_test ):
1929- return True
1930-
1931- for name in test_id .split ("." ):
1932- if fnmatch .fnmatchcase (name , match_test ):
1933- return True
1934- return False
1935- _filter_suite (suite , case_pred )
1939+ _filter_suite (suite , _match_test )
19361940 _run_suite (suite )
19371941
19381942#=======================================================================
Original file line number Diff line number Diff line change @@ -837,11 +837,20 @@ def test_method2(self):
837837 pass
838838 """ )
839839 testname = self .create_test (code = code )
840+
841+ # Test --list-cases
840842 all_methods = ['%s.Tests.test_method1' % testname ,
841843 '%s.Tests.test_method2' % testname ]
842844 output = self .run_tests ('--list-cases' , testname )
843845 self .assertEqual (output .splitlines (), all_methods )
844846
847+ # Test --list-cases with --match
848+ all_methods = ['%s.Tests.test_method1' % testname ]
849+ output = self .run_tests ('--list-cases' ,
850+ '-m' , 'test_method1' ,
851+ testname )
852+ self .assertEqual (output .splitlines (), all_methods )
853+
845854 def test_crashed (self ):
846855 # Any code which causes a crash
847856 code = 'import faulthandler; faulthandler._sigsegv()'
You can’t perform that action at this time.
0 commit comments