Skip to content

Commit 6a421f7

Browse files
flying-sheepUbuntu
authored and
Ubuntu
committed
Cache data for subsequent test runs (scverse#3177)
1 parent e96cde2 commit 6a421f7

File tree

3 files changed

+13
-4
lines changed

3 files changed

+13
-4
lines changed

src/testing/scanpy/_pytest/__init__.py

+4-1
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919
@pytest.fixture(autouse=True)
2020
def _global_test_context(
2121
request: pytest.FixtureRequest,
22+
cache: pytest.Cache,
2223
tmp_path_factory: pytest.TempPathFactory,
2324
) -> Generator[None, None, None]:
2425
"""Switch to agg backend, reset settings, and close all figures at teardown."""
@@ -33,7 +34,9 @@ def _global_test_context(
3334
sc.settings.logfile = sys.stderr
3435
sc.settings.verbosity = "hint"
3536
sc.settings.autoshow = True
36-
sc.settings.datasetdir = tmp_path_factory.mktemp("scanpy_data")
37+
# reuse data files between test runs (unless overwritten in the test)
38+
sc.settings.datasetdir = cache.mkdir("scanpy-data")
39+
# create new writedir for each test run
3740
sc.settings.writedir = tmp_path_factory.mktemp("scanpy_write")
3841

3942
if isinstance(request.node, pytest.DoctestItem):

src/testing/scanpy/_pytest/fixtures/__init__.py

-3
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,6 @@ def float_dtype(request):
3939

4040
@pytest.fixture()
4141
def _doctest_env(cache: pytest.Cache, tmp_path: Path) -> Generator[None, None, None]:
42-
from scanpy import settings
4342
from scanpy._compat import chdir
4443

4544
showwarning_orig = warnings.showwarning
@@ -61,8 +60,6 @@ def showwarning(message, category, filename, lineno, file=None, line=None): # n
6160
] + [("ignore", None, Warning, None, 0)]
6261

6362
warnings.showwarning = showwarning
64-
old_dd, settings.datasetdir = settings.datasetdir, cache.mkdir("scanpy-data")
6563
with chdir(tmp_path):
6664
yield
6765
warnings.showwarning = showwarning_orig
68-
settings.datasetdir = old_dd

tests/test_datasets.py

+9
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,15 @@
2424
from anndata import AnnData
2525

2626

27+
@pytest.fixture(autouse=True)
28+
def _tmp_dataset_dir(tmp_path: Path) -> None:
29+
"""Make sure that datasets are downloaded during the test run.
30+
31+
The default test environment stores them in a cached location.
32+
"""
33+
sc.settings.datasetdir = tmp_path / "scanpy_data"
34+
35+
2736
@pytest.mark.internet
2837
def test_burczynski06():
2938
with pytest.warns(UserWarning, match=r"Variable names are not unique"):

0 commit comments

Comments
 (0)