Skip to content

scope=session fixtures setup/teardown multiple times #3470

@cielavenir

Description

@cielavenir

__init__.py

import pytest
import inspect
@pytest.fixture(scope="session")
def F(request):
  print('setup')
  yield inspect.stack()[0]
  print('teardown')

test_1.py

from . import F
def test_1(F):
  print(F)

test_2.py

from . import F
def test_2(F):
  print(F)

this pytest tree shows:

test_1.py setup
(<frame object at 0x7ff2c97fa730>)
.                                                                                                                                                              
test_2.py setup
(<frame object at 0x7ff2c97faaa0>)
.teardown
teardown

I expect setup/teardown only once, since there are only one fixture definition.

If this is because global session fixtures are gathered multiple times, I think this can be fixed by checking module name in gathering.

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