Skip to content

Cache data for subsequent test runs #3177

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Jul 30, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 4 additions & 1 deletion src/testing/scanpy/_pytest/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
@pytest.fixture(autouse=True)
def _global_test_context(
request: pytest.FixtureRequest,
cache: pytest.Cache,
tmp_path_factory: pytest.TempPathFactory,
) -> Generator[None, None, None]:
"""Switch to agg backend, reset settings, and close all figures at teardown."""
Expand All @@ -33,7 +34,9 @@ def _global_test_context(
sc.settings.logfile = sys.stderr
sc.settings.verbosity = "hint"
sc.settings.autoshow = True
sc.settings.datasetdir = tmp_path_factory.mktemp("scanpy_data")
# reuse data files between test runs (unless overwritten in the test)
sc.settings.datasetdir = cache.mkdir("scanpy-data")
# create new writedir for each test run
sc.settings.writedir = tmp_path_factory.mktemp("scanpy_write")

if isinstance(request.node, pytest.DoctestItem):
Expand Down
3 changes: 0 additions & 3 deletions src/testing/scanpy/_pytest/fixtures/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,6 @@ def float_dtype(request):

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

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

warnings.showwarning = showwarning
old_dd, settings.datasetdir = settings.datasetdir, cache.mkdir("scanpy-data")
with chdir(tmp_path):
yield
warnings.showwarning = showwarning_orig
settings.datasetdir = old_dd
9 changes: 9 additions & 0 deletions tests/test_datasets.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,15 @@
from anndata import AnnData


@pytest.fixture(autouse=True)
def _tmp_dataset_dir(tmp_path: Path) -> None:
"""Make sure that datasets are downloaded during the test run.

The default test environment stores them in a cached location.
"""
sc.settings.datasetdir = tmp_path / "scanpy_data"


@pytest.mark.internet
def test_burczynski06():
with pytest.warns(UserWarning, match=r"Variable names are not unique"):
Expand Down
Loading