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

session scoped fixtures get executed multiple times. I suspect I am using pytest wrong #1878

Closed
do3cc opened this issue Aug 26, 2016 · 2 comments

Comments

@do3cc
Copy link

do3cc commented Aug 26, 2016

Hi,

I am using pytest 3.0.1.

I've created a lot of test fixtures and wanted to push them to module scope.
I now see exceptions that show that they get executed twice.

I suspect that by importing my fixtures from one test module to another, I created a second session scoped fixture.

So in test_a.py I do:

fixture
def a():
    pass

and in test_b.py I do:

from .test_a import a

def test_lala(a):
    pass

Can you confirm my suspicion?

@RonnyPfannschmidt
Copy link
Member

due to importing py.test sees 2 different fixtures at different locations

there should probably bea warning about that one

@nicoddemus
Copy link
Member

I suggest to move your fixtures to a conftest.py file, importing them is really not recommended because it might bring some problems as @RonnyPfannschmidt mentioned.

Just create a conftest.py file at the root of your test files and put your fixtures there and they will be available automatically for all test modules below it.

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

No branches or pull requests

4 participants