Skip to content

fix(pytest): capture logs for fixture setup failures#471

Merged
gibiw merged 2 commits intomainfrom
fix/capture-logs-on-fixture-setup-failure
Mar 26, 2026
Merged

fix(pytest): capture logs for fixture setup failures#471
gibiw merged 2 commits intomainfrom
fix/capture-logs-on-fixture-setup-failure

Conversation

@gibiw
Copy link
Copy Markdown
Contributor

@gibiw gibiw commented Mar 26, 2026

Summary

  • When a test fails during fixture setup, pytest reports it as ERROR and the call phase never runs
  • The previous condition call.when == "call" meant _attach_logs was never invoked for setup-phase failures
  • log.txt, stdout.txt, and stderr.txt were missing from Qase results for these errors
  • Extended the condition to also attach logs when call.when == "setup" and report.failed
  • Unlike PR fix(pytest): capture logs for fixture setup failures (ERROR results) #470, this avoids duplicate attachments for passing tests by only capturing setup logs on failure

Changes

  • qase-pytest/src/qase/pytest/plugin.py — extended log attachment condition to cover setup failures
  • qase-pytest/tests/tests_qase_pytest/test_plugin.py — 4 unit tests covering the new behavior via hookwrapper simulation
  • examples/single/pytest/tests/test_fixture_setup_failure.py — example tests demonstrating the fix

Test plan

  • Unit tests: test_logs_attached_on_setup_failure — logs captured on fixture ERROR
  • Unit tests: test_logs_not_attached_on_setup_success — no duplication for passing tests
  • Unit tests: test_logs_still_attached_on_call_phase — existing behavior preserved
  • Unit tests: test_logs_not_attached_when_capture_logs_disabled — respects config
  • Integration: example tests produce correct JSON report with attachments

Closes #470 (alternative implementation)

gibiw added 2 commits March 26, 2026 11:12
When a test fails during fixture setup, pytest reports it as ERROR and
the call phase never runs. The previous condition `call.when == "call"`
meant _attach_logs was never invoked for setup-phase failures, so
log.txt, stdout.txt, and stderr.txt were missing from Qase results.

Extend the condition to also attach logs when `call.when == "setup"` and
`report.failed`, ensuring setup-failure logs are captured without
duplicating attachments for passing tests.
@gibiw gibiw merged commit 6baf2c6 into main Mar 26, 2026
36 checks passed
@gibiw gibiw deleted the fix/capture-logs-on-fixture-setup-failure branch March 26, 2026 08:24
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.

1 participant