pytest-dev / pytest-dev/pytest
Recursive parameterized fixture bug
Nobody has claimed this yet.
- Dominant language
- Python
- Stars
- 14.5k
- Forks
- 3.4k
- Avg merge
- 2d 9h
- Merged PRs (30d)
- 35
Description
Description
When overriding session scoped fixtures with a parameterized fixture that is used as the input to another fixture the recursive fixture is not properly invoked.
I have created a minimal reproduction here with more information: https://github.com/baszalmstra/pytest_fixture_bug
Minimal example
Given the files:
conftest.py
import pytest
@pytest.fixture(scope="session")
def parameterized_fixture(request):
return request.param
@pytest.fixture(scope="session")
def recursive_fixture(parameterized_fixture):
print("Calling recursive_fixture with: {}".format(parameterized_fixture))
return parameterized_fixture
test_bar.py
import pytest
@pytest.fixture(scope="session", params=["bar1"])
def parameterized_fixture(request):
print("Calling parameterized_fixture with: {}".format(request.param))
return request.param
def test_bar(recursive_fixture):
print("Calling test_foo with: {}".format(recursive_fixture))
assert("bar" in recursive_fixture)
test_foo.py
import pytest
@pytest.fixture(scope="session", params=["foo1", "foo2"])
def parameterized_fixture(request):
print("Calling parameterized_fixture with: {}".format(request.param))
return request.param
def test_foo(recursive_fixture):
print("Calling test_bar with: {}".format(recursive_fixture))
assert("foo" in recursive_fixture)
Calling pytest fails with:
________________________________ test_foo[foo1] ________________________________
recursive_fixture = 'bar1'
def test_foo(recursive_fixture):
print("Calling test_bar with: {}".format(recursive_fixture))
> assert("foo" in recursive_fixture)
E AssertionError: assert 'foo' in 'bar1'
test_foo.py:12: AssertionError
---------------------------- Captured stdout setup -----------------------------
Calling parameterized_fixture with: foo1
----------------------------- Captured stdout call -----------------------------
Calling test_bar with: bar1
Which should not be possible.
We have observed this issue with both pytest-4.6.9 as well as with pytest-5.3.2 on Ubuntu 18.04. We are still on python 2.7 so a backported solution to pytest 4 would be desirable.
This seems to be related to: #5693
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start by reproducing the failure with the conftest.py, test_bar.py, and test_foo.py examples in the issue, then compare the behavior with related issue #5693. Trace how the session-scoped recursive_fixture resolves the overridden parameterized_fixture. Done means each test receives its own parameter value instead of the value from another module, with coverage for the reported Python 2.7-compatible behavior.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- python
- Domain
- testing-qa
- Issue type
- Bug
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Quiet
- Clarity
- Clearly specified
- Newbie friendliness
- 45/100