Skip to content

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

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

mgorny
Copy link
Contributor

@mgorny mgorny commented Mar 16, 2021

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

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.
@github-actions
Copy link

This PR is stale because it has been open for 30 days with no activity.

@github-actions github-actions bot added the stale Stale PR or inactive for long period of time. label Apr 16, 2021

.. versionchanged:: 3.4
Returns ``False`` if there were any :attr:`unexpectedSuccesses`
from tests marked with the :func:`expectedFailure` decorator.

.. versionchanged:: 3.10b1
Copy link
Member

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``.
Copy link
Member

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:
Copy link
Member

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.

@github-actions github-actions bot removed the stale Stale PR or inactive for long period of time. label Aug 5, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants