-
Notifications
You must be signed in to change notification settings - Fork 154
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Restrict files written by tests (#1061)
Co-authored-by: Isaac Virshup <[email protected]> Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>
- Loading branch information
1 parent
fea7561
commit 2c8759d
Showing
4 changed files
with
75 additions
and
26 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,15 +1,37 @@ | ||
# This file exists just to allow ignoring warnings without test collection failing on CI | ||
# TODO: Fix that | ||
# This file exists | ||
# 1. to allow ignoring warnings without test collection failing on CI | ||
# 2. as a pytest plugin/config that applies to doctests as well | ||
# TODO: Fix that, e.g. with the `pytest -p anndata.testing._pytest` pattern. | ||
|
||
from pathlib import Path | ||
|
||
import pytest | ||
|
||
from anndata.compat import chdir | ||
|
||
|
||
doctest_marker = pytest.mark.usefixtures("doctest_env") | ||
|
||
|
||
@pytest.fixture | ||
def doctest_env(cache: pytest.Cache, tmp_path: Path) -> None: | ||
from scanpy import settings | ||
|
||
old_dd, settings.datasetdir = settings.datasetdir, cache.mkdir("scanpy-data") | ||
with chdir(tmp_path): | ||
yield | ||
settings.datasetdir = old_dd | ||
|
||
|
||
def pytest_itemcollected(item): | ||
"""Defining behavior of pytest.mark.gpu""" | ||
"""Define behavior of pytest.mark.gpu and doctests.""" | ||
from importlib.util import find_spec | ||
|
||
gpu = len([mark for mark in item.iter_markers(name="gpu")]) > 0 | ||
|
||
if gpu: | ||
is_gpu = len([mark for mark in item.iter_markers(name="gpu")]) > 0 | ||
if is_gpu: | ||
item.add_marker( | ||
pytest.mark.skipif(not find_spec("cupy"), reason="Cupy not installed.") | ||
) | ||
|
||
if isinstance(item, pytest.DoctestItem): | ||
item.add_marker(doctest_marker) |