Skip to content

Conversation

@jimsynz
Copy link
Contributor

@jimsynz jimsynz commented Jan 23, 2026

Summary

  • Fixture teardown failures are now correctly reported as failed tests
  • Previously, only setup and call phase outcomes were captured, so teardown failures would leave a test marked as "passed"

Fixes #84

Changes

1. Report teardown failures

The condition in pytest_runtest_logreport now handles teardown failures the same way it handles setup failures - capturing them to override the test result.

# Before
if report.when == 'call' or (report.when == 'setup' and report.failed):

# After  
if report.when == 'call' or (report.when in ('setup', 'teardown') and report.failed):

2. Fix xdist option access when xdist not installed

The numprocesses option only exists when pytest-xdist is installed. Previously, config.getoption("numprocesses") was called unconditionally, causing a ValueError when xdist wasn't present. This was breaking CI.

Test plan

  • Added test test_pytest_runtest_logreport_fail_exception_in_teardown that verifies teardown failure overrides a passed call result
  • All existing tests pass (63 total)
  • Tests run without error when xdist is not installed

Previously, only setup and call phase outcomes were considered when
determining test results. If a fixture teardown failed, the test would
still be reported as passed to Buildkite Test Analytics.

This change extends the phase check to also capture teardown failures,
which will override a passed call result. This matches pytest's own
behaviour where teardown failures cause the overall test to fail.

Fixes buildkite#84
The `numprocesses` option only exists when pytest-xdist is installed.
Previously, `config.getoption("numprocesses")` was called unconditionally,
causing a ValueError when xdist wasn't present.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Failures on teardown are ignored and the test is reported as passed

1 participant