-
-
Notifications
You must be signed in to change notification settings - Fork 31.9k
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?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -2012,13 +2012,16 @@ Loading and running tests | |
|
||
.. method:: wasSuccessful() | ||
|
||
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``. | ||
|
||
.. 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 commentThe reason will be displayed to describe this comment to others. Learn more. This will probably need to be 3.11 now. |
||
Returns ``False`` if no tests were found. | ||
|
||
.. method:: stop() | ||
|
||
This method can be called to signal that the set of tests being run should | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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 commentThe reason will be displayed to describe this comment to others. Learn more. I'd abstract the |
||
self.stream.writeln("Ran %d test%s in %.3fs" % | ||
(run, run != 1 and "s" or "", timeTaken)) | ||
else: | ||
self.stream.writeln("No tests found") | ||
self.stream.writeln() | ||
|
||
expectedFails = unexpectedSuccesses = skipped = 0 | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
:func:`unittest.TestResult.wasSuccessful` now returns False if no tests were | ||
found. |
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".