Add possibility to pass parameter to the fixture from another fixture
See original GitHub issueCould you please implement possibility to pass parameter from one fixture to the parent one? I have a complex fixture hierarchy in my test framework. I have some cases when i really need to have this feature.
Example:
@pytest.fixture(scope='session')
def fixture_1(request):
return request.param
@pytest.fixture
def fixture_2(fixture_1): # Need to pass parameter here to fixture_1
print (fixture_1)
So far I can pass parameter to the fixture from test using:
@pytest.mark.parametrize('fixture_1', ['parameter'], indirect=True)
def test_1(fixture_1):
print (fixture_1)
Need to have exactly the same thing from fixture.
Thank you!
Issue Analytics
- State:
- Created 7 years ago
- Reactions:8
- Comments:12 (7 by maintainers)
Top Results From Across the Web
How to pass a parameterised fixture as a parameter to another ...
2 Answers 2 ; import pytest @pytest.fixture(scope='function') def ; request): first_arg, second_arg = request.param s = Namespace() s.one = ...
Read more >How to use fixtures — pytest documentation
Once pytest finds them, it runs those fixtures, captures what they returned (if anything), and passes those objects into the test function as...
Read more >Five Advanced Pytest Fixture Patterns - Inspired Python
Factory Fixture: Fixtures with Arguments. Passing arguments to a fixture is the first thing people want to do with fixtures when they start...
Read more >Deep dive into Pytest parametrization | by George Shuklin
The fixture called as many times as the number of elements in the iterable of params argument, and the test function is called...
Read more >Pass Params to Pytest Fixture - Jake Trent
fixture decorator. It is identified by name. The thing that the generator function yields is the fixture value. When the generator is resumed, ......
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
@sathishaMovvar - You pinged me but I think you meant to ping @nicoddemus instead.
@nchammas thanks for the suggestion, but this still doesn’t solve my problem. the lazy fixture returns an object with only one value for parametrize. I want to use a list of values from the fixture which is used as params in the test.
below code work with lazy fixture but that’s not what I want.
instead I want something like below:
in which I get error “TypeError: ‘LazyFixture’ object is not iterable”. I found an open question in StackOverflolw similar to my scenario -https://stackoverflow.com/questions/50482416/use-pytest-lazy-fixture-list-values-as-parameters-in-another-fixture