-
-
Notifications
You must be signed in to change notification settings - Fork 3k
Open
Description
Short description
When a fixture fails during its setup, request.node.add_report_section calls made in the teardown sections of its (fixture) dependencies are "ignored", i.e. don't end up in the final report output printed to the terminal.
Minimal example
import pytest
@pytest.fixture
def fixture1(request):
request.node.add_report_section('setup', 'hello', 'during setup')
yield
request.node.add_report_section('teardown', 'hello', 'during teardown')
@pytest.fixture
def fixture2(fixture1):
assert False
def test_simple(fixture2):
passRunning this produces:
===================== ERRORS =====================
_________ ERROR at setup of test_simple __________
fixture1 = None
@pytest.fixture
def fixture2(fixture1):
> assert False
E assert False
test_foo.py:11: AssertionError
-------------- Captured hello setup --------------
during setup
============ short test summary info =============
ERROR test_foo.py::test_simple - assert False
================ 1 error in 0.04s ================
Expected behavior
There should be another section Captured hello teardown with content during teardown.
Actual behavior
See above: Only the setup report section ended up in the final report.
Additional notes
Note that the teardown section does run, as can be checked by having it write to a file or something like that. Only adding something to the report doesn't work.
Related issues
- During teardown, it's not possible to use
request.node.add_report_section#1448- I adapted the code for the minimal example from this one, which seems to have been fixed long ago. The only difference is that, in this new issue here, a dependent fixture fails instead of a dependent test.
System information
- pytest 9.0.2
- Ubuntu 24.04
Output of pip list
I used uvx pytest so basically:
$ uvx --with pytest pip list
Package Version
--------- -------
iniconfig 2.3.0
packaging 26.0
pip 26.0
pluggy 1.6.0
Pygments 2.19.2
pytest 9.0.2
Reactions are currently unavailable
Metadata
Metadata
Assignees
Labels
No labels