Skip to content
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

how to use fixture chain? #5970

Closed
bglmmz opened this issue Oct 16, 2019 · 3 comments
Closed

how to use fixture chain? #5970

bglmmz opened this issue Oct 16, 2019 · 3 comments
Labels
topic: fixtures anything involving fixtures directly or indirectly type: question general question, might be closed after 2 weeks of inactivity

Comments

@bglmmz
Copy link

bglmmz commented Oct 16, 2019

I defined a session fixture in conftest.py, and the fixture returns a global env,

@pytest.fixture(scope="session", autouse=True)
def global_test_env(request):
    ...
    global_env = create_env_impl()
    yield global_env 
    ....

Now I difined another module fixture in xxx.py,and this fixture want to retrieve the global_env created in session fixture. How to approach this? Like below?

@pytest.fixture(scope='module',autouse=True)
def custom_env(global_test_env):
    #retrieve the global_env like this?
    global_env = global_test_env

    do something else...
    my_env = create_my_evn()
    yield my_env    
    ....

@The-Compiler
Copy link
Member

That looks good, yup!

@bglmmz
Copy link
Author

bglmmz commented Oct 16, 2019

@RonnyPfannschmidt RonnyPfannschmidt added the type: question general question, might be closed after 2 weeks of inactivity label Oct 16, 2019
@Zac-HD Zac-HD added the topic: fixtures anything involving fixtures directly or indirectly label Oct 17, 2019
@Zac-HD
Copy link
Member

Zac-HD commented Oct 17, 2019

Answered on StackOverflow 😄

FYI you can have syntax highlighting for code blocks on Github.

@Zac-HD Zac-HD closed this as completed Oct 17, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
topic: fixtures anything involving fixtures directly or indirectly type: question general question, might be closed after 2 weeks of inactivity
Projects
None yet
Development

No branches or pull requests

4 participants