Skip to content

Commit

Permalink
Backport PR #1459 on branch 0.10.x (Move tests out of package) (#1486)
Browse files Browse the repository at this point in the history
  • Loading branch information
flying-sheep authored May 2, 2024
1 parent 0c3de0c commit 6bd4e8a
Show file tree
Hide file tree
Showing 49 changed files with 36 additions and 52 deletions.
13 changes: 1 addition & 12 deletions .azure-pipelines.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,7 @@ trigger:

variables:
RUN_COVERAGE: no
# TODO: remove paths after moving tests to test dir: https://github.com/scverse/anndata/issues/1451
PYTEST_ADDOPTS: --color=yes --junitxml=test-data/test-results.xml anndata ./src/anndata/tests ./docs/concatenation.rst
PYTEST_ADDOPTS: --color=yes --junitxml=test-data/test-results.xml
DEPENDENCIES_VERSION: "latest" # |"pre-release" | "minimum-version"
TEST_TYPE: "standard" # | "coverage"

Expand Down Expand Up @@ -85,16 +84,6 @@ jobs:
displayName: "PyTest (treat warnings as errors)"
condition: eq(variables['TEST_TYPE'], 'strict-warning')
# TODO: remove: https://github.com/scverse/anndata/issues/1451
- task: PythonScript@0
inputs:
scriptSource: inline
script: |
import sys, xml.etree.ElementTree as ET
results = ET.parse("./test-data/test-results.xml").findall("./*/*")
sys.exit(0 if len(results) > 3000 else f"Error: only {len(results)} tests run")
displayName: "Check if enough tests ran"

- task: PublishCodeCoverageResults@2
inputs:
codeCoverageTool: Cobertura
Expand Down
8 changes: 4 additions & 4 deletions .codecov.yml
Original file line number Diff line number Diff line change
@@ -1,16 +1,16 @@
# Based on pydata/xarray
codecov:
require_ci_to_pass: no
require_ci_to_pass: false

coverage:
status:
project:
default:
# Require 1% coverage, i.e., always succeed
target: 1
# Require 80% coverage
target: 80
changes: false

comment:
layout: "diff, flags, files"
behavior: once
require_base: no
require_base: false
11 changes: 11 additions & 0 deletions conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,17 @@
from pathlib import Path


# TODO: Should be done in pyproject.toml eventually
# See https://github.com/pytest-dev/pytest-cov/issues/437
def pytest_configure(config: pytest.Config) -> None:
config.addinivalue_line(
"filterwarnings", "ignore::anndata._warnings.OldFormatWarning"
)
config.addinivalue_line(
"filterwarnings", "ignore::anndata._warnings.ExperimentalFeatureWarning"
)


@pytest.fixture(autouse=True)
def _suppress_env_for_doctests(request: pytest.FixtureRequest) -> None:
if isinstance(request.node, pytest.DoctestItem):
Expand Down
21 changes: 7 additions & 14 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ doc = [
]
test = [
"loompy>=3.0.5",
"pytest>=8.0",
"pytest>=8.2",
"pytest-cov>=2.10",
"zarr",
"matplotlib",
Expand All @@ -101,12 +101,6 @@ test = [
]
gpu = ["cupy"]

[tool.hatch.build]
exclude = [
"src/anndata/tests/conftest.py",
"src/anndata/tests/test_*.py",
"src/anndata/tests/data",
]
[tool.hatch.version]
source = "vcs"
[tool.hatch.build.hooks.vcs]
Expand All @@ -125,18 +119,16 @@ exclude_also = [

[tool.pytest.ini_options]
addopts = [
# "--import-mode=importlib", # TODO: enable: https://github.com/scverse/anndata/issues/1451
"--import-mode=importlib",
"--strict-markers",
"--doctest-modules",
"--pyargs",
"--ignore=anndata/core.py", # deprecated
"--ignore=anndata/readwrite.py", # deprecated
]
filterwarnings = [
'ignore:Support for Awkward Arrays is currently experimental',
'ignore:Outer joins on awkward\.Arrays',
# TODO: replace both lines above with this one once we figured out how prevent ImportPathMismatchError
# 'ignore::anndata._warnings.ExperimentalFeatureWarning',
# all `ignore::anndata.*` entries are in `conftest.py`
# See: https://github.com/pytest-dev/pytest-cov/issues/437
]
# When `--strict-warnings` is used, all warnings are treated as errors, except those:
filterwarnings_when_strict = [
Expand All @@ -148,7 +140,8 @@ filterwarnings_when_strict = [
]
python_files = "test_*.py"
testpaths = [
"anndata", # docstrings and unit tests (module name due to --pyargs)
"anndata", # docstrings (module name due to --pyargs)
"./tests", # unit tests
"./docs/concatenation.rst", # further doctests
]
# For some reason this effects how logging is shown when tests are run
Expand Down Expand Up @@ -182,7 +175,7 @@ ignore = [
]
[tool.ruff.lint.per-file-ignores]
# E721 comparing types, but we specifically are checking that we aren't getting subtypes (views)
"src/anndata/tests/test_readwrite.py" = ["E721"]
"tests/test_readwrite.py" = ["E721"]
[tool.ruff.lint.isort]
known-first-party = ["anndata"]
required-imports = ["from __future__ import annotations"]
Expand Down
19 changes: 0 additions & 19 deletions src/anndata/tests/conftest.py

This file was deleted.

10 changes: 10 additions & 0 deletions tests/conftest.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
from __future__ import annotations

import pytest

from anndata.tests.helpers import subset_func # noqa: F401


@pytest.fixture
def backing_h5ad(tmp_path):
return tmp_path / "test.h5ad"
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
Original file line number Diff line number Diff line change
Expand Up @@ -467,21 +467,21 @@ def test_readloom_deprecations(tmp_path):


def test_read_csv():
adata = ad.read_csv(HERE / "adata.csv")
adata = ad.read_csv(HERE / "data" / "adata.csv")
assert adata.obs_names.tolist() == ["r1", "r2", "r3"]
assert adata.var_names.tolist() == ["c1", "c2"]
assert adata.X.tolist() == X_list


def test_read_tsv_strpath():
adata = ad.read_text(str(HERE / "adata-comments.tsv"), "\t")
adata = ad.read_text(str(HERE / "data" / "adata-comments.tsv"), "\t")
assert adata.obs_names.tolist() == ["r1", "r2", "r3"]
assert adata.var_names.tolist() == ["c1", "c2"]
assert adata.X.tolist() == X_list


def test_read_tsv_iter():
with (HERE / "adata-comments.tsv").open() as f:
with (HERE / "data" / "adata-comments.tsv").open() as f:
adata = ad.read_text(f, "\t")
assert adata.obs_names.tolist() == ["r1", "r2", "r3"]
assert adata.var_names.tolist() == ["c1", "c2"]
Expand Down
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.

0 comments on commit 6bd4e8a

Please # to comment.