Skip to content

Commit

Permalink
Backport PR #2879 on branch 1.10.x (Fix pytest deprecation warning) (#…
Browse files Browse the repository at this point in the history
…2880)

Co-authored-by: Philipp A <[email protected]>
  • Loading branch information
meeseeksmachine and flying-sheep authored Feb 23, 2024
1 parent 48b495d commit 2be2eb0
Show file tree
Hide file tree
Showing 5 changed files with 20 additions and 26 deletions.
7 changes: 7 additions & 0 deletions docs/release-notes/1.10.0.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,10 @@
### 1.10.0rc2 {small}`2024-02-22`

```{rubric} Bug fixes
```

* Fix pytest deprecation warning {pr}`2879` {smaller}`P Angerer`

### 1.10.0rc1 {small}`2024-02-22`

```{rubric} Features
Expand Down
12 changes: 7 additions & 5 deletions scanpy/__init__.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
"""Single-Cell Analysis in Python."""
from __future__ import annotations

import sys

try: # See https://github.com/maresb/hatch-vcs-footgun-example
from setuptools_scm import get_version

Expand All @@ -21,6 +23,11 @@

# the actual API
# (start with settings as several tools are using it)

from ._settings import Verbosity, settings

set_figure_params = settings.set_figure_params

from anndata import (
AnnData,
concat,
Expand All @@ -38,15 +45,10 @@
from . import plotting as pl
from . import preprocessing as pp
from . import tools as tl
from ._settings import Verbosity, settings
from .neighbors import Neighbors
from .readwrite import read, read_10x_h5, read_10x_mtx, read_visium, write

set_figure_params = settings.set_figure_params

# has to be done at the end, after everything has been imported
import sys

sys.modules.update({f"{__name__}.{m}": globals()[m] for m in ["tl", "pp", "pl"]})
from ._utils import annotate_doc_types

Expand Down
16 changes: 1 addition & 15 deletions scanpy/testing/_doctests.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,22 +9,8 @@
def doctest_needs(mod: str) -> Callable[[F], F]:
"""Mark function with doctest dependency."""

try:
from ._pytest.marks import needs
except ImportError:
mark = None
else:
try:
mark = needs[mod]
except KeyError:
raise KeyError(
f"Unknown dependency {mod}. If it isn’t a typo, "
"please add it to `needs` enum in `scanpy.testing._pytests.marks`."
) from None

def decorator(func: F) -> F:
if mark is not None:
func._doctest_needs = mark
func._doctest_needs = mod
return func

return decorator
Expand Down
9 changes: 4 additions & 5 deletions scanpy/testing/_pytest/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,12 +10,11 @@

from ..._utils import _import_name
from .fixtures import * # noqa: F403
from .marks import needs

if TYPE_CHECKING:
from collections.abc import Generator, Iterable

from .marks import needs


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

func = _import_name(request.node.name)
needs_marker: needs | None
if needs_marker := getattr(func, "_doctest_needs", None):
assert needs_marker.mark.name == "skipif"
needs_mod: str | None
if needs_mod := getattr(func, "_doctest_needs", None):
needs_marker = needs[needs_mod]
if needs_marker.mark.args[0]:
pytest.skip(reason=needs_marker.mark.kwargs["reason"])
skip_reason: str | None
Expand Down
2 changes: 1 addition & 1 deletion scanpy/testing/_pytest/marks.py
Original file line number Diff line number Diff line change
Expand Up @@ -57,4 +57,4 @@ def __init__(self, mod: str) -> None:
if self._name_.casefold() != mod.casefold().replace("-", "_"):
reason = f"{reason} (`pip install {mod}`)"
dec = pytest.mark.skipif(not find_spec(self._name_), reason=reason)
super().__init__(dec.mark)
super().__init__(dec.mark, _ispytest=True)

0 comments on commit 2be2eb0

Please sign in to comment.