bpo-30523: regrtest --list-cases --match (#2401) · python/cpython@ace56d5 (original) (raw)
Navigation Menu
- Explore
- Pricing
Provide feedback
Saved searches
Use saved searches to filter your results more quickly
Appearance settings
Commit ace56d5
* regrtest --list-cases now supports --match and --match-file options. Example: ./python -m test --list-cases -m FileTests test_os * --list-cases now also sets support.verbose to False to prevent messages to stdout when loading test modules. * Add support._match_test() private function.
File tree
3 files changed
lines changed
3 files changed
lines changed
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -256,9 +256,13 @@ def _list_cases(self, suite): | ||
256 | 256 | if isinstance(test, unittest.TestSuite): |
257 | 257 | self._list_cases(test) |
258 | 258 | elif isinstance(test, unittest.TestCase): |
259 | -print(test.id()) | |
259 | +if support._match_test(test): | |
260 | +print(test.id()) | |
260 | 261 | |
261 | 262 | def list_cases(self): |
263 | +support.verbose = False | |
264 | +support.match_tests = self.ns.match_tests | |
265 | + | |
262 | 266 | for test in self.selected: |
263 | 267 | abstest = get_abs_module(self.ns, test) |
264 | 268 | try: |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1905,6 +1905,23 @@ def _run_suite(suite): | ||
1905 | 1905 | raise TestFailed(err) |
1906 | 1906 | |
1907 | 1907 | |
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 | + | |
1908 | 1925 | def run_unittest(*classes): |
1909 | 1926 | """Run tests from unittest.TestCase-derived classes.""" |
1910 | 1927 | valid_types = (unittest.TestSuite, unittest.TestCase) |
@@ -1919,20 +1936,7 @@ def run_unittest(*classes): | ||
1919 | 1936 | suite.addTest(cls) |
1920 | 1937 | else: |
1921 | 1938 | 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) | |
1936 | 1940 | _run_suite(suite) |
1937 | 1941 | |
1938 | 1942 | #======================================================================= |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -837,11 +837,20 @@ def test_method2(self): | ||
837 | 837 | pass |
838 | 838 | """) |
839 | 839 | testname = self.create_test(code=code) |
840 | + | |
841 | +# Test --list-cases | |
840 | 842 | all_methods = ['%s.Tests.test_method1' % testname, |
841 | 843 | '%s.Tests.test_method2' % testname] |
842 | 844 | output = self.run_tests('--list-cases', testname) |
843 | 845 | self.assertEqual(output.splitlines(), all_methods) |
844 | 846 | |
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 | + | |
845 | 854 | def test_crashed(self): |
846 | 855 | # Any code which causes a crash |
847 | 856 | code = 'import faulthandler; faulthandler._sigsegv()' |