-
-
Notifications
You must be signed in to change notification settings - Fork 3k
Account for changes in fixture dependencies properly #14104
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
Anton3
wants to merge
22
commits into
pytest-dev:main
Choose a base branch
from
Anton3:param-fixtures-deps
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+1,355
−98
Open
Changes from all commits
Commits
Show all changes
22 commits
Select commit
Hold shift + click to select a range
c78734c
Initial
Anton3 ba0ba86
Always fixture finish in teardown phase
Anton3 643afdf
Fix current_item_index
Anton3 1553d3f
Use nextitem to teardown stale fixtures
Anton3 917ff33
Fix exception handling
Anton3 455bdbb
Rewrite everything, add more tests
Anton3 e7c31fa
Add changelogs
Anton3 e9df3c1
Fix coverage
Anton3 5aef1d5
Fix changelogs
Anton3 54a3a35
Remove fixture finalizers as they become stale
Anton3 35eb82b
Fix typing
Anton3 2151943
Fix docs
Anton3 3e156b3
Expand changelog entries
Anton3 7f11150
Fix coverage
Anton3 3b69c2b
Catch TEST_OUTCOME, fix _finish_if_param_changed
Anton3 07a0a0c
Fix coverage
Anton3 25f5820
Merge branch 'main' into param-fixtures-deps
Anton3 60f4286
Use TypeAlias
Anton3 d88ccd9
Move finalizers management to SetupState
Anton3 4301de7
Minor diff cleanups
Anton3 dfcff79
Use double quotes in changelog's snippet
Anton3 a4b6489
Restart flaky test_timeout_and_exit
Anton3 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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()``. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
this one needs a explaining comment