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

Is dynamic updation of fixture scope possible ? #2300

Closed
4 tasks
tejas3190 opened this issue Mar 10, 2017 · 2 comments
Closed
4 tasks

Is dynamic updation of fixture scope possible ? #2300

tejas3190 opened this issue Mar 10, 2017 · 2 comments
Labels
type: question general question, might be closed after 2 weeks of inactivity

Comments

@tejas3190
Copy link

tejas3190 commented Mar 10, 2017

Like using the same fixture that may have a different scope for setup & teardown based on test cases calling? Are this possible, Thanks

Here's a quick checklist in what to include:

  • Include a detailed description of the bug or suggestion
  • pip list of the virtual environment you are using
  • pytest and operating system versions
  • Minimal example if possible
@nicoddemus
Copy link
Member

Hi,

This is not possible, and probably very hard (impossible?) to implement in the current architecture. I would recommend just using different fixture names. You can avoid duplication by making the fixture call another function which is responsible to create the fixture value. For example:

@pytest.fixture(scope='session')
def foo_session():
    return create_foo()

@pytest.fixture(scope='module')
def foo_module():
    return create_foo()

And so on. Then each fixture can decide the scope as usual.

I'm closing this for now but feel free to follow up with any questions.

@RonnyPfannschmidt RonnyPfannschmidt added the type: question general question, might be closed after 2 weeks of inactivity label Mar 10, 2017
@tejas3190
Copy link
Author

Thanks for the suggestion @nicoddemus Great work 👍

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
type: question general question, might be closed after 2 weeks of inactivity
Projects
None yet
Development

No branches or pull requests

3 participants