8000 gh-62432: unittest runner: Exit code 5 if no tests were run by stefanor · Pull Request #102051 · python/cpython · GitHub
[go: up one dir, main page]

Skip to content

gh-62432: unittest runner: Exit code 5 if no tests were run #102051

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 13 commits into from
Apr 27, 2023
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

10000
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Next Next commit
Refactor test_program to allow for multiple test suites
  • Loading branch information
stefanor committed Feb 19, 2023
commit 0a2007dad63bd30ac66925f802feb9ee6418b40e
22 changes: 13 additions & 9 deletions Lib/test/test_unittest/test_program.py
Original file line number Diff line number Diff line change
Expand Up @@ -71,15 +71,19 @@ def testExpectedFailure(self):
def testUnexpectedSuccess(self):
pass

class FooBarLoader(unittest.TestLoader):
"""Test loader that returns a suite containing FooBar."""
class TestLoader(unittest.TestLoader):
"""Test loader that returns a suite containing testsuite."""

def __init__(self, testcase):
self.testcase = testcase

def loadTestsFromModule(self, module):
return self.suiteClass(
[self.loadTestsFromTestCase(Test_TestProgram.FooBar)])
[self.loadTestsFromTestCase(self.testcase)])

def loadTestsFromNames(self, names, module):
return self.suiteClass(
[self.loadTestsFromTestCase(Test_TestProgram.FooBar)])
[self.loadTestsFromTestCase(self.testcase)])

def test_defaultTest_with_string(self):
class FakeRunner(object):
Expand All @@ -92,7 +96,7 @@ def run(self, test):
runner = FakeRunner()
program = unittest.TestProgram(testRunner=runner, exit=False,
defaultTest='test.test_unittest',
testLoader=self.FooBarLoader())
testLoader=self.TestLoader(self.FooBar))
sys.argv = old_argv
self.assertEqual(('test.test_unittest',), program.testNames)

Expand All @@ -108,7 +112,7 @@ def run(self, test):
program = unittest.TestProgram(
testRunner=runner, exit=False,
defaultTest=['test.test_unittest', 'test.test_unittest2'],
testLoader=self.FooBarLoader())
testLoader=self.TestLoader(self.FooBar))
sys.argv = old_argv
self.assertEqual(['test.test_unittest', 'test.test_unittest2'],
program.testNames)
Expand All @@ -118,7 +122,7 @@ def test_NonExit(self):
program = unittest.main(exit=False,
argv=["foobar"],
testRunner=unittest.TextTestRunner(stream=stream),
testLoader=self.FooBarLoader())
testLoader=self.TestLoader(self.FooBar))
self.assertTrue(hasattr(program, 'result'))
out = stream.getvalue()
self.assertIn('\nFAIL: testFail ', out)
Expand All @@ -136,7 +140,7 @@ def test_Exit(self):
argv=["foobar"],
testRunner=unittest.TextTestRunner(stream=stream),
exit=True,
testLoader=self.FooBarLoader())
testLoader=self.TestLoader(self.FooBar))
out = stream.getvalue()
self.assertIn('\nFAIL: testFail ', out)
self.assertIn('\nERROR: testError ', out)
Expand All @@ -152,7 +156,7 @@ def test_ExitAsDefault(self):
unittest.main,
argv=["foobar"],
testRunner=unittest.TextTestRunner(stream=stream),
testLoader=self.FooBarLoader())
testLoader=self.TestLoader(self.FooBar))
out = stream.getvalue()
self.assertIn('\nFAIL: testFail ', out)
self.assertIn('\nERROR: testError ', out)
Expand Down
0