Skip to content

Commit 2be2eb0

Browse files
Backport PR #2879 on branch 1.10.x (Fix pytest deprecation warning) (#2880)
Co-authored-by: Philipp A <[email protected]>
1 parent 48b495d commit 2be2eb0

File tree

5 files changed

+20
-26
lines changed

5 files changed

+20
-26
lines changed

Diff for: docs/release-notes/1.10.0.md

+7
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,10 @@
1+
### 1.10.0rc2 {small}`2024-02-22`
2+
3+
```{rubric} Bug fixes
4+
```
5+
6+
* Fix pytest deprecation warning {pr}`2879` {smaller}`P Angerer`
7+
18
### 1.10.0rc1 {small}`2024-02-22`
29

310
```{rubric} Features

Diff for: scanpy/__init__.py

+7-5
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
"""Single-Cell Analysis in Python."""
22
from __future__ import annotations
33

4+
import sys
5+
46
try: # See https://github.com/maresb/hatch-vcs-footgun-example
57
from setuptools_scm import get_version
68

@@ -21,6 +23,11 @@
2123

2224
# the actual API
2325
# (start with settings as several tools are using it)
26+
27+
from ._settings import Verbosity, settings
28+
29+
set_figure_params = settings.set_figure_params
30+
2431
from anndata import (
2532
AnnData,
2633
concat,
@@ -38,15 +45,10 @@
3845
from . import plotting as pl
3946
from . import preprocessing as pp
4047
from . import tools as tl
41-
from ._settings import Verbosity, settings
4248
from .neighbors import Neighbors
4349
from .readwrite import read, read_10x_h5, read_10x_mtx, read_visium, write
4450

45-
set_figure_params = settings.set_figure_params
46-
4751
# has to be done at the end, after everything has been imported
48-
import sys
49-
5052
sys.modules.update({f"{__name__}.{m}": globals()[m] for m in ["tl", "pp", "pl"]})
5153
from ._utils import annotate_doc_types
5254

Diff for: scanpy/testing/_doctests.py

+1-15
Original file line numberDiff line numberDiff line change
@@ -9,22 +9,8 @@
99
def doctest_needs(mod: str) -> Callable[[F], F]:
1010
"""Mark function with doctest dependency."""
1111

12-
try:
13-
from ._pytest.marks import needs
14-
except ImportError:
15-
mark = None
16-
else:
17-
try:
18-
mark = needs[mod]
19-
except KeyError:
20-
raise KeyError(
21-
f"Unknown dependency {mod}. If it isn’t a typo, "
22-
"please add it to `needs` enum in `scanpy.testing._pytests.marks`."
23-
) from None
24-
2512
def decorator(func: F) -> F:
26-
if mark is not None:
27-
func._doctest_needs = mark
13+
func._doctest_needs = mod
2814
return func
2915

3016
return decorator

Diff for: scanpy/testing/_pytest/__init__.py

+4-5
Original file line numberDiff line numberDiff line change
@@ -10,12 +10,11 @@
1010

1111
from ..._utils import _import_name
1212
from .fixtures import * # noqa: F403
13+
from .marks import needs
1314

1415
if TYPE_CHECKING:
1516
from collections.abc import Generator, Iterable
1617

17-
from .marks import needs
18-
1918

2019
# Defining it here because it’s autouse.
2120
@pytest.fixture(autouse=True)
@@ -113,9 +112,9 @@ def _modify_doctests(request: pytest.FixtureRequest) -> None:
113112
request.getfixturevalue("_doctest_env")
114113

115114
func = _import_name(request.node.name)
116-
needs_marker: needs | None
117-
if needs_marker := getattr(func, "_doctest_needs", None):
118-
assert needs_marker.mark.name == "skipif"
115+
needs_mod: str | None
116+
if needs_mod := getattr(func, "_doctest_needs", None):
117+
needs_marker = needs[needs_mod]
119118
if needs_marker.mark.args[0]:
120119
pytest.skip(reason=needs_marker.mark.kwargs["reason"])
121120
skip_reason: str | None

Diff for: scanpy/testing/_pytest/marks.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -57,4 +57,4 @@ def __init__(self, mod: str) -> None:
5757
if self._name_.casefold() != mod.casefold().replace("-", "_"):
5858
reason = f"{reason} (`pip install {mod}`)"
5959
dec = pytest.mark.skipif(not find_spec(self._name_), reason=reason)
60-
super().__init__(dec.mark)
60+
super().__init__(dec.mark, _ispytest=True)

0 commit comments

Comments
 (0)