Driver FixRecommendedSound, Wi-Fi or graphics acting up? Check drivers firstFind missing or outdated drivers fast.Check DriversOctober DealsAmazon USOctober deal check: compare before you payAmazon US: current deals, useful picks and tech finds.Check DealsSlow PC?RecommendedPC slow today? Run a repair scan before it gets worseResolve common Windows issues and optimize system performance.Scan Now×
Skip to content
World desk2 min

pytest Failed: What a Passing Test Run Really Means

Pytest exit code 1 means some collected and run tests failed—not that every test failed. Learn how rerun options work and what a passing retry can tell you.
Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

Yes—a pytest run can fail even when other collected tests pass. Exit code 1 means tests were collected and run, but some failed; it does not mean every test failed. The session result and each test’s result are different things.

Why pytest can fail when some tests pass

Pytest reports a session-level exit code as well as individual test outcomes. A session can include both passing and failing tests, and still exit with code 1. The official exit-code reference distinguishes that result from a fully passing run and from a run with no collected tests.

As an Amazon Associate I earn from qualifying purchases.

Exit code Meaning
0 All tests were collected and passed.
1 Tests were collected and run, but some failed.
5 No tests were collected.

So “pytest failed” describes the invocation, not necessarily every test item in it. In a CI job, inspect the test results or failure report to see which items passed and which failed; the exit code alone does not provide that breakdown.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

Choose a rerun option based on what you need to run

Pytest’s rerun options differ in whether they run only remembered failures, the entire suite, or stop at the next failure. These options rely on pytest’s cache, so check the installed version and project configuration before assuming identical behavior across repositories.

Command What it runs Important distinction
pytest --lf or pytest --last-failed Tests pytest remembers as failed in the previous run. With no remembered failures, the default is to run all tests. --last-failed-no-failures can change the no-known-failures behavior to all or none.
pytest --ff or pytest --failed-first The full suite, with remembered failures scheduled first. This is not a failures-only retry. The changed order can affect fixture setup and teardown.
pytest --sw or pytest --stepwise Tests until a failure occurs; a later invocation continues from the last failing test. Useful for working through failures incrementally, but not a normal full-suite run.

Pytest documents cache inspection with pytest --cache-show and cache removal with pytest --cache-clear. Clearing the cache removes the remembered state that influences options such as --lf and stepwise execution. The pytest cache guide explains the cache behavior.

Independent reader supportYour contribution helps us test, update, and keep practical guides available for everyone.Support on Ko-Fi

What it means when a failed test passes on retry

A test that fails intermittently or sporadically is flaky, in pytest’s terminology. A passing retry may be evidence of intermittent behavior, but it does not reveal the cause or prove the original failure was harmless. Pytest’s flaky-test guidance identifies uncontrolled system state as a broad source of inconsistency.

Investigate what differed between the failing and passing attempts rather than treating the retry as a fix. In particular, check:

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.
  • Cleanup and test data left behind by earlier tests.
  • Whether the result changes with test order or when tests run in parallel.
  • Shared state or thread-safety issues.
  • Assertions that may be stricter than the behavior being tested warrants.
  • Environmental conditions that vary between attempts.

Reruns can be useful in CI: pytest says that “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 is a mitigation, not a diagnosis. A retry that passes does not establish that the underlying inconsistency has been resolved.

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.

Leave a Reply

Your email address will not be published. Required fields are marked *

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

More from the Wire

  1. World desk4 min
    How to Spot an AI Voice Scam Before Sending MoneyDon’t rely on how a caller sounds. Pause, call back through a known number, and verify the emergency with another trusted person before sending money.
  2. Mountain View desk4 min
    Google’s SynthID Detector: How to Check AI-Generated Images, Video and AudioGoogle’s SynthID Detector looks for an embedded watermark in supported images, video and audio. Here is what its results do—and do not—show.
  3. Redmond desk20 min
    How to create a link to File or Folder in Windows 11Windows 11 gives you several ways to point to a file or folder without moving or duplicating it. You can create a desktop shortcut,…
Recommended PC Tool
Recommended PC Tool
Windows Errors? Fix Them Before They SpreadFree repair scan
Outdated Drivers Are Slowing You DownFree scan - exact matches

Two free Windows tools

One Free Minute Could Fix That PC

Before you go - each of these free tools takes about a minute and tackles what quietly slows a Windows PC down.

Special offer. View Outbyte info, uninstall instructions, EULA, and Privacy Policy.