Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions changelog/14103.bugfix.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Fixtures are now rebuilt when param changes for a fixture they depend on, if the dependency is via ``request.getfixturevalue()``.
1 change: 1 addition & 0 deletions changelog/14114.bugfix.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
An exception from ``pytest_fixture_post_finalizer`` no longer prevents fixtures from being torn down, causing additional errors in the following tests.
1 change: 1 addition & 0 deletions changelog/2043.bugfix.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
If a fixture depends on a fixture that becomes hidden in a test (compared to the previous test), the hidden fixture definition is no longer executed.
3 changes: 3 additions & 0 deletions changelog/4871.improvement.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
Garbage finalizers for fixture teardown are no longer accumulated in nodes and fixtures.

:func:`Node.addfinalizer <_pytest.nodes.Node.addfinalizer>` and ``request.addfinalizer()`` now return a handle that allows to remove the finalizer.
1 change: 1 addition & 0 deletions changelog/5848.improvement.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
``pytest_fixture_post_finalizer`` is no longer called extra times for the same fixture teardown.
47 changes: 47 additions & 0 deletions changelog/9287.bugfix.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
Teardown of parametrized fixtures now happens in the teardown stage of the test before the parameter changes.

Previously teardown would happen in the setup stage of the test where the parameter changes.

If a test forces teardown of a parametrized fixture, e.g. using ``request.getfixturevalue()``, it instead fails. An example of such test:

.. code-block:: pytest

# conftest.py
import pytest

@pytest.hookimpl(wrapper=True, tryfirst=True)
def pytest_collection_modifyitems(items):
# Disable built-in test reordering.
original_items = items[:]
yield
items[:] = original_items

# test_invalid.py
import pytest

@pytest.fixture(scope="session")
def foo(request):
return getattr(request, "param", "default")

@pytest.mark.parametrize("foo", [1], indirect=True)
def test_a(foo):
assert foo == 1

def test_b(request):
request.getfixturevalue("foo")

@pytest.mark.parametrize("foo", [1], indirect=True)
def test_c(foo):
assert foo == 1

This produces the following error:

.. code-block:: console

Parameter for the requested fixture changed unexpectedly in test:
test_invalid.py::test_b
Requested fixture 'foo' defined in:
test_invalid.py:4

Previous parameter value: 1
New parameter value: None
7 changes: 7 additions & 0 deletions doc/en/reference/reference.rst
Original file line number Diff line number Diff line change
Expand Up @@ -993,6 +993,13 @@ ExitCode
:members:


FinalizerHandle
~~~~~~~~~~~~~~~

.. autoclass:: pytest.FinalizerHandle()
:members:


FixtureDef
~~~~~~~~~~

Expand Down
Loading