-
-
Notifications
You must be signed in to change notification settings - Fork 31.8k
bpo-18232: Return unsuccessfully if no unit tests were run #24893
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
base: main
Are you sure you want to change the base?
Conversation
Change unittest.TestResult.wasSuccessful() to return False if no tests were found. Update the runner to explicitly print "No tests found" to indicate the problem better. Add a test ensuring that wasSuccessful() still returns True if all tests were skipped, including the special case of SkipTest exception in setUpClass() method. This aids greatly with automated testing where an unexpected breakage of test discovery could not be caught cleanly, as the test runner returned success if no tests were found. This is unlikely to be the expected behavior in real usage.
This PR is stale because it has been open for 30 days with no activity. |
|
||
.. versionchanged:: 3.4 | ||
Returns ``False`` if there were any :attr:`unexpectedSuccesses` | ||
from tests marked with the :func:`expectedFailure` decorator. | ||
|
||
.. versionchanged:: 3.10b1 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This will probably need to be 3.11 now.
Return ``True`` if all tests run so far have passed, otherwise returns | ||
``False``. | ||
Return ``True`` if all tests run so far have passed and at least one test | ||
was found, otherwise returns ``False``. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The code checks testsRun + testsSkipped > 0, so it's not exactly "was found" (what if many were found but we haven't started running anything yet?)
nit: I think it's easier to understand if the sentence lists the conditions chronologically, something like: "at least one test has been executed or skipped and no test has failed so far".
@@ -184,8 +184,11 @@ def run(self, test): | |||
if hasattr(result, 'separator2'): | |||
self.stream.writeln(result.separator2) | |||
run = result.testsRun | |||
self.stream.writeln("Ran %d test%s in %.3fs" % | |||
(run, run != 1 and "s" or "", timeTaken)) | |||
if run > 0 or len(result.skipped) > 0: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'd abstract the run > 0 or len(result.skipped)
calculation as a method on TestResult
, then you won't have it repeated twice. And you can give it a name indicating what it means.
Change unittest.TestResult.wasSuccessful() to return False if no tests
were found. Update the runner to explicitly print "No tests found"
to indicate the problem better. Add a test ensuring that
wasSuccessful() still returns True if all tests were skipped, including
the special case of SkipTest exception in setUpClass() method.
This aids greatly with automated testing where an unexpected breakage
of test discovery could not be caught cleanly, as the test runner
returned success if no tests were found. This is unlikely to be
the expected behavior in real usage.
https://bugs.python.org/issue18232