Skip to content

@pytest.fixture(scope="package") works like session if placed in one file and used with pytest_plugins in conftest.py #7232

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

Open
twitt opened this issue May 20, 2020 · 0 comments
Labels
topic: fixtures anything involving fixtures directly or indirectly

Comments

@twitt
Copy link

twitt commented May 20, 2020

Hello.
I'm using pytest==5.4.1.
I have conftest.py file in root of the directory with content like this:

pytest_plugins = ['fixtures.configuration', 'fixtures.global']

my fixtures are placed in separate folder 'fixtures'.

When I run some fixture, which is defined in fixtures.configuration with scope "package" it's executed as session fixture. So I suppose this package scope realted to where fixtures are placed, than to where they're called. Is it expected behavior? if I want to use pytest_plugins in conftest.py this looks a bit inconvenient.

This can be tested by.

Creating conftest.py in root of directory with content:

pytest_plugins = ['fixtures.myfixtures']

Creating fixtures folder with myfxitures.py file inside of it with content.

@pytest.fixture(scope="package")
def hello_package():
      print('hello')
      yield
      print('world')

Creating package 'some' with two packages inside: 'hello', 'world'.

with files inside with content like
hello_test.py

def test_hello(hello_package):
        pass

world_test.py

def test_world(hello_package):
        pass

running: pytest -sv some

result:

collected 2 items                                                                                                                                                                                                                        

some/hello/hello_test.py::test_hello setup
PASSED
some/hworld/world_test.py::test_world PASSEDteardown

expected result:

collected 2 items                                                                                                                                                                                                                        

some/hello/hello_test.py::test_hello setup
PASSEDteardown

some/hworld/world_test.py::test_world setup
PASSEDteardown
@twitt twitt changed the title @pytest.fixture(scope="package") works like session if placed in one conftest.py @pytest.fixture(scope="package") works like session if placed in one file and used with pytest_plugins in conftest.py May 20, 2020
@Zac-HD Zac-HD added the topic: fixtures anything involving fixtures directly or indirectly label May 21, 2020
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
Projects
None yet
Development

No branches or pull requests

2 participants