pytest-lazy-fixture doesn't work for deep nesting
See original GitHub issuepytest-lazy-fixture doesn’t work for deep nesting
platform linux – Python 3.5.2, pytest-3.10.1, py-1.7.0, pluggy-0.8.1 plugins: timeout-1.3.0, celery-4.2.1, repeat-0.7.0, reportportal-1.0.4, assume-1.2, lazy-fixture-0.5.1
Example:
import pytest
@pytest.fixture(scope='function')
def fixt1():
return 111
@pytest.fixture(scope='function')
def fixt2():
return pytest.lazy_fixture("fixt1")
@pytest.fixture(scope='function')
def fixt3():
return pytest.lazy_fixture("fixt2")
def test(fixt3):
print("Value in test: {}".format(fixt3))
Returns:
Value in test: <LazyFixture "fixt1">
Should be:
Value in test: 111
Issue Analytics
- State:
- Created 5 years ago
- Comments:5 (3 by maintainers)
Top Results From Across the Web
Pytest parametrized fixture with pytest-lazy-fixture fails if ...
Clearly debugging the plugin manager of pytest is unfeasible but I noticed the pytest_configure function inside pytest-lazy-fixture never gets ...
Read more >Python pytest - The Blue Book
Pytest. pytest is a Python framework to makes it easy to write small tests, yet scales to support complex functional testing for applications...
Read more >4. Writing Great Code - The Hitchhiker's Guide to Python [Book]
This chapter focuses on best practices for writing great Python code. ... available for importing deeply nested packages: import very.deep.module as mod ....
Read more >Changelog — Schemathesis 3.17.5 documentation
Internal error when Schemathesis doesn't have permission to create its ... Ignored Open API specific keywords & types in schemas with deeply nested...
Read more >Best Practices - Apache Airflow
The DAG that has simple linear structure A -> B -> C will experience less delays in task scheduling than DAG that has...
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
This is a relatively old post, but
pytest-cases
might be a solution for you. Itsparametrize_plus
decorator supports referencing fixtures that are themselves parametrized, withfixture_ref
.In short
pytest-cases
provides a generalization of the greatpytest-lazy-fixture
to support more complex use-cases such as parametrization of lazy fixtures (and many other things such as fixture unions, etc.)@bigbZik The main problem to get such a thing working on the long term is that pytest has two logical phases: first, all tests (with different parametrizations) are collected; and only then all tests (and necessary fixtures) are executed.
So in your example, only when
fixt3
gets executed,pytest.lazy_fixture("fixt2")
gets returned. So iffixt2
would be parametrized, there’d be no way fortest
to be instantiated multiple times during test collection.But in this case, what’s the problem with these two alternatives?
or