Skip to content

A fixture defined in a class is not itself!? (since 8.4.0) #13751

@maread99

Description

@maread99
import pytest

class TestCls:
    @pytest.fixture
    def a_fixture():
        yield

TestCls.a_fixture is TestCls.a_fixture
False
TestCls.a_fixture == TestCls.a_fixture
False

Prior to 8.4.0 both these statements returned True, as might be expected...?

Perhaps this is related to #13479?

This came to my attention as a result of this test failing. The test ensures some fixtures aren't being overridden by a subclass. If the issue I've raised here isn't considered a bug, perhaps you could you suggest an alternative means to verify that fixtures aren't being overridden?

Thank you!

os: windows
environment:

Package               Version
--------------------- -----------
asttokens             3.0.0
attrs                 25.3.0
build                 1.3.0
click                 8.3.0
colorama              0.4.6
comm                  0.2.3
debugpy               1.8.17
decorator             5.2.1
exceptiongroup        1.3.0
execnet               2.1.1
executing             2.2.1
hypothesis            6.140.2
iniconfig             2.1.0
ipykernel             6.30.1
ipython               8.37.0
jedi                  0.19.2
jupyter_client        8.6.3
jupyter_core          5.8.1
korean-lunar-calendar 0.3.1
matplotlib-inline     0.1.7
nest-asyncio          1.6.0
numpy                 2.2.6
packaging             25.0
pandas                2.3.2
parso                 0.8.5
pip                   25.2
pip-tools             7.5.0
platformdirs          4.4.0
pluggy                1.6.0
prompt_toolkit        3.0.52
psutil                7.1.0
pure_eval             0.2.3
py-cpuinfo            9.0.0
Pygments              2.19.2
pyluach               2.3.0
pyproject_hooks       1.2.0
pytest                8.4.2
pytest-benchmark      5.1.0
pytest-xdist          3.8.0
python-dateutil       2.9.0.post0
pytz                  2025.2
pywin32               311
pyzmq                 27.1.0
ruff                  0.13.1
setuptools            58.1.0
six                   1.17.0
sortedcontainers      2.4.0
stack-data            0.6.3
tomli                 2.2.1
toolz                 1.0.0
tornado               6.5.2
traitlets             5.14.3
typing_extensions     4.15.0
tzdata                2025.2
wcwidth               0.2.14
wheel                 0.45.1
  • a detailed description of the bug or problem you are having
  • output of pip list from the virtual environment you are using
  • pytest and operating system versions
  • minimal example if possible

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions