Skip to content

Conversation

bigbZik
Copy link

@bigbZik bigbZik commented Sep 5, 2018

Example:

@pytest.fixture(scope="class")
def fix1():
    return "fix1_result"

@pytest.fixture(scope="function")
def some_fixture0():
    yield pytest.lazy_fixture("fix1")

@pytest.fixture(scope="function")
def some_fixture1(some_fixture0):
    yield "some_" + some_fixture0

@pytest.fixture(scope="function")
def some_fixture2(some_fixture1):
    yield "more_" + some_fixture1

def test1(some_fixture2):
    assert some_fixture2 == "more_some_fix1_result"

Example 2:

@pytest.fixture
def one(request):
    return "SOME_VALUE"

@pytest.fixture
def two(request):
    return "SOME_VALUE2"

@pytest.fixture(params=["one", "two"])
def anoter_fixture1(request):
    return pytest.lazy_fixture(request.param)

@pytest.fixture
def anoter_fixture2(anoter_fixture1):
    return "NEW_" + anoter_fixture1

def test2(anoter_fixture2):
    assert ((anoter_fixture2 == "NEW_SOME_VALUE") or (anoter_fixture2 == "NEW_SOME_VALUE2"))

@bigbZik
Copy link
Author

bigbZik commented Sep 10, 2018

Do you have any comments?

@TvoroG
Copy link
Owner

TvoroG commented Sep 10, 2018

@bigbZik, Hi! Thanks for contribution! I'll check it out for sure on this week. Sorry for not answering)

@TvoroG
Copy link
Owner

TvoroG commented Sep 16, 2018

Hey! Thanks again, but I'm not sure this function is the right way to solve the problem:

def get_fixture_value(fname, request):
    res = request.getfixturevalue(fname)
    while is_lazy_fixture(res):
        res = request.getfixturevalue(res.name)
    return res

I was able to solve first test only for now. Check out https://github.com/TvoroG/pytest-lazy-fixture/tree/pull28.

I will need more time for test_lazy_fixture_nested_fixtures_in_parametrize test.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants