-
-
Notifications
You must be signed in to change notification settings - Fork 3k
Open
Labels
topic: fixturesanything involving fixtures directly or indirectlyanything involving fixtures directly or indirectlytype: refactoringinternal improvements to the codeinternal improvements to the code
Description
I have an inherited fixture from a baseclass. From searching this can work 63292928.
However my example uses a class scope which does then not work.
The provided example will fail both tests. When removing the scope of the fixture both tests will pass.
import pytest
class Base:
name = None
variable = None
def setup(self):
self.variable = self.name
print(f"setup: {self.variable}")
def teardown(self):
print(f"teardown: {self.variable}")
@pytest.fixture(scope="class")
def fix(self):
try:
self.setup()
yield
finally:
self.teardown()
@pytest.mark.usefixtures("fix")
class Test1(Base):
name = "test1"
def test_a(self):
assert self.variable == self.name
@pytest.mark.usefixtures("fix")
class Test2(Base):
name = "test2"
def test_a(self):
assert self.variable == self.name
- a detailed description of the bug or problem you are having
- output of
pip listfrom the virtual environment you are using
$ pip list
Package Version
--------- -------
iniconfig 2.3.0
packaging 25.0
pip 25.0
pluggy 1.6.0
Pygments 2.19.2
pytest 9.0.1
- pytest and operating system versions
Ubuntu 25.04 plucky ; Python 3.13.3 - minimal example if possible
Metadata
Metadata
Assignees
Labels
topic: fixturesanything involving fixtures directly or indirectlyanything involving fixtures directly or indirectlytype: refactoringinternal improvements to the codeinternal improvements to the code