Skip to content

fix: keep artifacts when a fixture fails during teardown - #330

Merged
Pavel Feldman (pavelfeldman) merged 2 commits into
mainfrom
fix-117-artifacts-on-teardown-failure
Oct 8, 2026
Merged

Pavel Feldman (pavelfeldman) merged 2 commits into
mainfrom
fix-117-artifacts-on-teardown-failure

Conversation

@pavelfeldman

@pavelfeldman Pavel Feldman (pavelfeldman) commented Oct 7, 2026 •

Copy link
Copy Markdown
Member

With --tracing/--video retain-on-failure or --screenshot only-on-failure, artifacts were discarded when a user fixture failed during teardown (e.g. a logged_in(page) fixture whose logout step raises). The recorder decided in its own fixture teardown, which runs before such failures are reported. Setup failures already kept artifacts.

  • Videos are now copied out of Playwright in the fixture teardown, so everything that needs Playwright (and await in the asyncio plugin) still happens there. Under --video retain-on-failure this is one extra file copy per page for every test, passing ones included; before, passing tests only deleted the video.
  • If the test has already failed, artifacts are kept right away, as before. Otherwise keeping or discarding them is deferred to pytest_runtest_makereport for the teardown report, which reflects failures from every fixture.
  • A test skipped from a fixture (pytest.skip() during setup) no longer counts as failed. Before, retain-on-failure kept a test-failed-1.png and a trace for it.
  • The pytest_runtest_makereport wrapper now runs trylast, so pytest_runtest_makereport hooks in conftest.py and in other plugins see the outcome it sets on the teardown report.
  • The session temp folder is now cleaned up via config.add_cleanup, because the last test's teardown report comes after session fixtures are torn down.
  • A filesystem error while moving deferred artifacts is reported as a teardown error of that test, not an INTERNALERROR that aborts the run. If a fixture already failed in teardown, its traceback stays the main one and the artifact error is added as a report section.

Tests: fixtures failing in setup and in teardown keep the screenshot, trace and video, a fixture that skips keeps nothing, and a failing shutil.move produces teardown errors with both messages (sync + async).

Fixes #117

Stack created with GitHub Stacks CLI • Give Feedback 💬

@pavelfeldman
Pavel Feldman (pavelfeldman) added this pull request to stack #335 October 7, 2026 23:05
@pavelfeldman
Pavel Feldman (pavelfeldman) force-pushed the fix-117-artifacts-on-teardown-failure branch from 186d1ed to bd65cd1 Compare October 8, 2026 01:32
@pavelfeldman
Pavel Feldman (pavelfeldman) force-pushed the fix-117-artifacts-on-teardown-failure branch from bd65cd1 to c090b7b Compare October 8, 2026 01:42
Base automatically changed from feat-205-launch-args-param to main October 8, 2026 01:43
With --tracing/--video retain-on-failure or --screenshot only-on-failure,
artifacts were discarded when a user fixture (e.g. one that uses `page`)
failed during teardown: the recorder decided in its own fixture teardown,
which runs before such failures are reported.

Videos are now copied out of Playwright in the fixture teardown, and when the
test has not failed yet, keeping or discarding the artifacts is deferred to
pytest_runtest_makereport for the teardown report. The session temp folder is
now cleaned up at the end of the run, since the last test's teardown report
comes after session fixtures are torn down.

Fixes #117
…ests skipped from a fixture, keep the fixture's own teardown error, test the artifact error path
@pavelfeldman
Pavel Feldman (pavelfeldman) force-pushed the fix-117-artifacts-on-teardown-failure branch from c090b7b to 7cc6e8f Compare October 8, 2026 01:43
@pavelfeldman
Pavel Feldman (pavelfeldman) merged commit 4607d7c into main Oct 8, 2026
15 checks passed
@pavelfeldman
Pavel Feldman (pavelfeldman) deleted the fix-117-artifacts-on-teardown-failure branch October 8, 2026 02:09
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.

retain-on-failure discards trace/video if teardown/setup fails in fixtures

1 participant