Outdated Drivers Are Slowing You Down
One free scan finds every outdated or missing driver and matches the right update for your exact hardware.Free scan · exact hardware matchPC Slower Than It Used to Be?
A free scan shows the junk files, broken settings and background clutter dragging Windows down - then fixes them in one click.Free scan · Windows 10 & 11iTechGuides is reader-supported. When you buy through links on our site, we may earn an affiliate commission. As an Amazon Associate I earn from qualifying purchases. Learn more
Yes—a pytest run can fail even when many collected tests pass. Exit code 1 means pytest collected and ran tests, but some failed; it does not mean every test failed. The key is to separate the result of the whole invocation from the outcome of each test.
Why pytest can report failure when tests passed
Pytest reports both individual test outcomes and an overall session result. A session can therefore include passing tests alongside one or more failures and still end with a nonzero exit code. In pytest’s exit-code reference, code 1 means tests were collected and run, but some failed.
That is different from code 5, which means no tests were collected. Code 0 means all collected tests passed. So if your log shows passes and pytest exits with code 1, look for at least one failure in the same run rather than assuming the passing tests should make the session successful.
Choose the right pytest rerun option
Pytest’s rerun controls are not interchangeable: one selects remembered failures, another runs everything but changes the order, and a third stops and resumes step by step.
#1 Best Overall
| Command | What it runs | What to watch for |
|---|---|---|
pytest --lf or pytest --last-failed |
Tests recorded as failed in the previous run. | Uses pytest’s cached last-failure state. If there are no remembered failures or no cache data, the default is to run all tests. The --last-failed-no-failures option can change the no-known-failures behavior to all or none. |
pytest --ff or pytest --failed-first |
The full suite, with remembered failures placed first. | This is not a retry of only failed tests. The changed order can affect fixture setup and teardown. |
pytest --sw or pytest --stepwise |
Runs tests until a failure, then stops; a later invocation continues from the last failing test. | Useful for working through failures incrementally, but it is not a normal full-suite run. |
These behaviors are documented in pytest’s execution-control options and cache guide. To inspect cache contents, run pytest --cache-show; to remove cached state, run pytest --cache-clear. The default cache provider is enabled unless the project disables or changes it.
Before relying on a rerun command in a particular repository, check the installed pytest version and project configuration. Cache state determines what --lf and stepwise mode select, while --ff deliberately changes test order.
What a passing retry does—and does not—tell you
If a test fails once and passes on retry, it may be flaky: pytest describes flaky tests as tests that fail intermittently or sporadically. A passing retry shows that the test passed on that attempt; it does not explain the original failure or prove that it was harmless.
Do these 3 things before closing this tab:
1Clear out junk files and repair common Windows errors2Fix the driver behind crashes, sound loss and screen glitches3Repair Windows errors before they cause bigger problemsPytest’s flaky-test guidance points to uncontrolled system state as a broad cause, including dependence on cleanup, test ordering, prior test data, or parallel execution. It also notes overly strict assertions and thread-safety concerns. Use the failure and retry as evidence to investigate, not as a repair by themselves.
- Check whether the test depends on data or state left by another test.
- Review setup and cleanup, especially if the failure changes when test order changes.
- Consider concurrency and shared resources when tests run in parallel.
- Re-examine assertions and thread-safety where they could make outcomes intermittent.
Pytest’s documentation says, “Rerunning any failed tests can mitigate the negative effects of flaky tests by giving them additional chances to pass, so that the overall build does not fail.” That can help limit the effect of intermittent failures in CI, but it does not identify or fix their cause.
Independent reader supportYour contribution helps us test, update, and keep practical guides available for everyone.Distinguish test failures from other nonzero exit codes
Not every nonzero pytest exit code means tests failed. The documented codes are:
0: all tests were collected and passed.1: tests were collected and run, but some failed.2: execution was interrupted by the user.3: an internal error occurred during test execution.4: a command-line usage error occurred.5: no tests were collected.6: the maximum number of warnings was exceeded.
When diagnosing a CI log, use the actual exit code and session output together. In particular, do not describe a collection problem, interruption, or usage error as a test failure.
Quick wins for a faster PC:
Repair Windows errors before they cause bigger problemsFix Now →Fix the driver behind crashes, sound loss and screen glitchesFind Drivers →Clear out junk files and repair common Windows errorsFree Scan →Quick Recap
Best Value
Product prices and availability are accurate as of the date/time indicated and are subject to change. Any price and availability information displayed on Amazon at the time of purchase will apply.

