Skip to content

Commit 73e1d4e

Browse files
committed
add pytest plugin
1 parent 5148550 commit 73e1d4e

File tree

2 files changed

+41
-0
lines changed

2 files changed

+41
-0
lines changed

setup.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,7 @@
4949
"vivarium_build_utils>=2.0.1,<3.0.0",
5050
"pyarrow",
5151
"seaborn",
52+
"layered-config-tree",
5253
# Type stubs
5354
"types-setuptools",
5455
]
@@ -69,6 +70,7 @@
6970
test_requirements = [
7071
"vivarium_dependencies[pytest]",
7172
"pytest-check",
73+
"vivarium_testing_utils",
7274
]
7375

7476
doc_requirements = [
@@ -124,6 +126,9 @@
124126
+ lint_requirements
125127
+ validation_requirements,
126128
},
129+
entry_points={
130+
"pytest11": ["vivarium_testing_utils = vivarium_testing_utils.pytest_plugin"],
131+
},
127132
zip_safe=False,
128133
use_scm_version={
129134
"write_to": "src/vivarium_testing_utils/_version.py",
Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
"""Pytest plugin providing common fixtures for vivarium projects.
2+
3+
This module is automatically loaded by pytest when vivarium_testing_utils is installed,
4+
via the pytest11 entry point defined in setup.py.
5+
"""
6+
7+
import pytest
8+
from layered_config_tree import LayeredConfigTree
9+
from pytest_mock import MockerFixture
10+
11+
12+
@pytest.fixture
13+
def no_gbd_cache(mocker: MockerFixture) -> None:
14+
"""Disable vivarium_gbd_access caching for test isolation.
15+
16+
This fixture mocks ``vivarium_gbd_access.utilities.get_input_config`` to return
17+
a configuration with ``cache_data`` set to False, ensuring that tests always
18+
pull fresh data rather than using cached results.
19+
20+
Note that this fixture does NOT use ``autouse=True``. If you want it to apply
21+
to all tests in a module or package, create a wrapper fixture in your conftest.py:
22+
23+
.. code-block:: python
24+
25+
import pytest
26+
27+
@pytest.fixture(autouse=True)
28+
def no_cache(no_gbd_cache):
29+
'''Apply no_gbd_cache to all tests in this module.'''
30+
pass
31+
32+
"""
33+
mocker.patch(
34+
"vivarium_gbd_access.utilities.get_input_config",
35+
return_value=LayeredConfigTree({"input_data": {"cache_data": False}}),
36+
)

0 commit comments

Comments
 (0)