Skip to content

Session scoped fixture is called twice #3217

Closed
@bdjellab

Description

@bdjellab

Hello,

Version: I'm running Ubuntu 14.04 with pytest 3.4.0.

Use case: I am using a session scoped fixture which I import and use in two different test files.

Issue: The fixture is run one time for each file when I expect it to be run only once for the whole session.

Example:

fixtures.py

import pytest

@pytest.fixture(scope="session")
def my_fixture():
    print "Hello"

test1.py

from fixtures import my_fixture

def test_example(my_fixture):
    pass

test2.py

from fixtures import my_fixture

def test_example2(my_fixture):
    pass

Hello is printed twice instead of once.

Workaround: A workaround is to import it in the conftest but since I am using hundred of fixtures, I prefer not to import everything in the conftest.

Metadata

Metadata

Assignees

No one assigned

    Labels

    topic: fixturesanything involving fixtures directly or indirectlytype: questiongeneral question, might be closed after 2 weeks of inactivity

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions