Skip to content

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
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".

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
@StanFromIreland
Copy link
Member

This was completed in 76632b8

@StanFromIreland StanFromIreland changed the title bpo-18232: Return unsuccessfully if no unit tests were run gh-62432: Return unsuccessfully if no unit tests were run Jul 28, 2025
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.

6 participants