Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 11 additions & 6 deletions Lib/test/libregrtest/findtests.py
Original file line number Diff line number Diff line change
Expand Up @@ -95,12 +95,17 @@ def list_cases(tests: TestTuple, *,
match_labels: TestFilter | None = None,
test_dir: StrPath | None = None) -> None:
support.verbose = False
cases_by_module, skipped = collect_cases(tests, match_tests=match_tests,
match_labels=match_labels,
test_dir=test_dir)
for cases in cases_by_module.values():
for case_id in cases:
print(case_id)
set_match_tests(match_tests, match_labels)

skipped = []
for test_name in tests:
module_name = abs_module_name(test_name, test_dir)
try:
suite = unittest.defaultTestLoader.loadTestsFromName(module_name)
_list_cases(suite)
except unittest.SkipTest:
skipped.append(test_name)

if skipped:
sys.stdout.flush()
stderr = sys.stderr
Expand Down
15 changes: 15 additions & 0 deletions Lib/test/test_regrtest.py
Original file line number Diff line number Diff line change
Expand Up @@ -1526,6 +1526,21 @@ def test_method2(self):
testname)
self.assertEqual(output.splitlines(), all_methods)

def test_list_cases_import_error(self):
# A test module which fails to import has no test case to list
code = textwrap.dedent("""
import unittest

class Tests(unittest.TestCase):
def test_method1(self):
pass
""")
testname = self.create_test(code=code)
broken = self.create_test(code='import nonexistent_module')
output = self.run_tests('--list-cases', broken, testname)
self.assertEqual(output.splitlines(),
['%s.Tests.test_method1' % testname])

@support.cpython_only
def test_crashed(self):
# Any code which causes a crash
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
Fix ``python -m test --list-cases`` listing the name of a test module that
fails to import.
Loading