You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
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
The problem:
Package fixtures are destroyed at the end of the pytest run, not at the end of the last test within the package, as the documentation says. This bug prevents different package-level fixtures from accessing the same resource (e.g., a docker container in my case).
The mitigation is to create an empty __init__.py, however as of Python3.3, this should not be mandatory (packages can be defined by the directory structure).
I put the repro in this repository for convenience, but it boils down to creating 2 tests, 1 module scope at top-level, and 1 at package level with a package-scope fixture defined in conftest. The fixture is destroyed after the toplevel test (incorrectly) if __init__.py is missing, otherwise it acts correctly (as implied by the doc + Python3 definition of a package at least) and is destroyed after the nested test.
The behavior should be either documented at the link above or changed.
Versions and such
Package Version Editable project location
-------------- ------- -------------------------
exceptiongroup 1.2.2
iniconfig 2.0.0
package 0.1.0 /home/akitov/pytest-repro
packaging 24.2
pip 24.3.1
pluggy 1.5.0
pytest 8.3.4
tomli 2.2.1
$ uname -a
Linux LL8FZ1VT3 6.8.0-51-generic #52~22.04.1-Ubuntu SMP PREEMPT_DYNAMIC Mon Dec 9 15:00:52 UTC 2 x86_64 x86_64 x86_64 GNU/Linux
The text was updated successfully, but these errors were encountered:
Checklist:
pip list
from the virtual environment you are usingThe problem:
Package fixtures are destroyed at the end of the pytest run, not at the end of the last test within the package, as the documentation says. This bug prevents different package-level fixtures from accessing the same resource (e.g., a docker container in my case).
The mitigation is to create an empty
__init__.py
, however as of Python3.3, this should not be mandatory (packages can be defined by the directory structure).I put the repro in this repository for convenience, but it boils down to creating 2 tests, 1 module scope at top-level, and 1 at package level with a package-scope fixture defined in conftest. The fixture is destroyed after the toplevel test (incorrectly) if
__init__.py
is missing, otherwise it acts correctly (as implied by the doc + Python3 definition of a package at least) and is destroyed after the nested test.The behavior should be either documented at the link above or changed.
Versions and such
The text was updated successfully, but these errors were encountered: