diff --git a/.azure-pipelines.yml b/.azure-pipelines.yml index 87974a34d..90b32de88 100644 --- a/.azure-pipelines.yml +++ b/.azure-pipelines.yml @@ -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" @@ -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 diff --git a/.codecov.yml b/.codecov.yml index 68cc92f2d..48f7a5e06 100644 --- a/.codecov.yml +++ b/.codecov.yml @@ -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 diff --git a/conftest.py b/conftest.py index 578bc71d9..8e7216015 100644 --- a/conftest.py +++ b/conftest.py @@ -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): diff --git a/pyproject.toml b/pyproject.toml index 183ffdcd8..f27cc4fd7 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -83,7 +83,7 @@ doc = [ ] test = [ "loompy>=3.0.5", - "pytest>=8.0", + "pytest>=8.2", "pytest-cov>=2.10", "zarr", "matplotlib", @@ -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] @@ -125,7 +119,7 @@ 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", @@ -133,10 +127,8 @@ addopts = [ "--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 = [ @@ -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 @@ -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"] diff --git a/src/anndata/tests/conftest.py b/src/anndata/tests/conftest.py deleted file mode 100644 index e45bf708b..000000000 --- a/src/anndata/tests/conftest.py +++ /dev/null @@ -1,19 +0,0 @@ -from __future__ import annotations - -import warnings - -import pytest - -import anndata -from anndata.tests.helpers import subset_func # noqa: F401 - -# TODO: Should be done in pyproject.toml, see anndata/conftest.py -warnings.filterwarnings("ignore", category=anndata.OldFormatWarning) - -# TODO: remove once we extricated test utils and tests -collect_ignore = ["helpers.py"] - - -@pytest.fixture -def backing_h5ad(tmp_path): - return tmp_path / "test.h5ad" diff --git a/tests/conftest.py b/tests/conftest.py new file mode 100644 index 000000000..22ec4b6bd --- /dev/null +++ b/tests/conftest.py @@ -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" diff --git a/src/anndata/tests/adata-comments.tsv b/tests/data/adata-comments.tsv similarity index 100% rename from src/anndata/tests/adata-comments.tsv rename to tests/data/adata-comments.tsv diff --git a/src/anndata/tests/adata.csv b/tests/data/adata.csv similarity index 100% rename from src/anndata/tests/adata.csv rename to tests/data/adata.csv diff --git a/src/anndata/tests/data/archives/readme.md b/tests/data/archives/readme.md similarity index 100% rename from src/anndata/tests/data/archives/readme.md rename to tests/data/archives/readme.md diff --git a/src/anndata/tests/data/archives/v0.7.0/adata.h5ad b/tests/data/archives/v0.7.0/adata.h5ad similarity index 100% rename from src/anndata/tests/data/archives/v0.7.0/adata.h5ad rename to tests/data/archives/v0.7.0/adata.h5ad diff --git a/src/anndata/tests/data/archives/v0.7.0/adata.zarr.zip b/tests/data/archives/v0.7.0/adata.zarr.zip similarity index 100% rename from src/anndata/tests/data/archives/v0.7.0/adata.zarr.zip rename to tests/data/archives/v0.7.0/adata.zarr.zip diff --git a/src/anndata/tests/data/archives/v0.7.8/adata.h5ad b/tests/data/archives/v0.7.8/adata.h5ad similarity index 100% rename from src/anndata/tests/data/archives/v0.7.8/adata.h5ad rename to tests/data/archives/v0.7.8/adata.h5ad diff --git a/src/anndata/tests/data/archives/v0.7.8/adata.zarr.zip b/tests/data/archives/v0.7.8/adata.zarr.zip similarity index 100% rename from src/anndata/tests/data/archives/v0.7.8/adata.zarr.zip rename to tests/data/archives/v0.7.8/adata.zarr.zip diff --git a/src/anndata/tests/data/excel.xlsx b/tests/data/excel.xlsx similarity index 100% rename from src/anndata/tests/data/excel.xlsx rename to tests/data/excel.xlsx diff --git a/src/anndata/tests/data/umi_tools.tsv.gz b/tests/data/umi_tools.tsv.gz similarity index 100% rename from src/anndata/tests/data/umi_tools.tsv.gz rename to tests/data/umi_tools.tsv.gz diff --git a/src/anndata/tests/test_anncollection.py b/tests/test_anncollection.py similarity index 100% rename from src/anndata/tests/test_anncollection.py rename to tests/test_anncollection.py diff --git a/src/anndata/tests/test_annot.py b/tests/test_annot.py similarity index 100% rename from src/anndata/tests/test_annot.py rename to tests/test_annot.py diff --git a/src/anndata/tests/test_awkward.py b/tests/test_awkward.py similarity index 100% rename from src/anndata/tests/test_awkward.py rename to tests/test_awkward.py diff --git a/src/anndata/tests/test_backed_sparse.py b/tests/test_backed_sparse.py similarity index 100% rename from src/anndata/tests/test_backed_sparse.py rename to tests/test_backed_sparse.py diff --git a/src/anndata/tests/test_base.py b/tests/test_base.py similarity index 100% rename from src/anndata/tests/test_base.py rename to tests/test_base.py diff --git a/src/anndata/tests/test_concatenate.py b/tests/test_concatenate.py similarity index 100% rename from src/anndata/tests/test_concatenate.py rename to tests/test_concatenate.py diff --git a/src/anndata/tests/test_concatenate_disk.py b/tests/test_concatenate_disk.py similarity index 100% rename from src/anndata/tests/test_concatenate_disk.py rename to tests/test_concatenate_disk.py diff --git a/src/anndata/tests/test_dask.py b/tests/test_dask.py similarity index 100% rename from src/anndata/tests/test_dask.py rename to tests/test_dask.py diff --git a/src/anndata/tests/test_dask_view_mem.py b/tests/test_dask_view_mem.py similarity index 100% rename from src/anndata/tests/test_dask_view_mem.py rename to tests/test_dask_view_mem.py diff --git a/src/anndata/tests/test_deprecations.py b/tests/test_deprecations.py similarity index 100% rename from src/anndata/tests/test_deprecations.py rename to tests/test_deprecations.py diff --git a/src/anndata/tests/test_get_vector.py b/tests/test_get_vector.py similarity index 100% rename from src/anndata/tests/test_get_vector.py rename to tests/test_get_vector.py diff --git a/src/anndata/tests/test_gpu.py b/tests/test_gpu.py similarity index 100% rename from src/anndata/tests/test_gpu.py rename to tests/test_gpu.py diff --git a/src/anndata/tests/test_hdf5_backing.py b/tests/test_hdf5_backing.py similarity index 100% rename from src/anndata/tests/test_hdf5_backing.py rename to tests/test_hdf5_backing.py diff --git a/src/anndata/tests/test_helpers.py b/tests/test_helpers.py similarity index 100% rename from src/anndata/tests/test_helpers.py rename to tests/test_helpers.py diff --git a/src/anndata/tests/test_inplace_subset.py b/tests/test_inplace_subset.py similarity index 100% rename from src/anndata/tests/test_inplace_subset.py rename to tests/test_inplace_subset.py diff --git a/src/anndata/tests/test_io_backwards_compat.py b/tests/test_io_backwards_compat.py similarity index 100% rename from src/anndata/tests/test_io_backwards_compat.py rename to tests/test_io_backwards_compat.py diff --git a/src/anndata/tests/test_io_conversion.py b/tests/test_io_conversion.py similarity index 100% rename from src/anndata/tests/test_io_conversion.py rename to tests/test_io_conversion.py diff --git a/src/anndata/tests/test_io_dispatched.py b/tests/test_io_dispatched.py similarity index 100% rename from src/anndata/tests/test_io_dispatched.py rename to tests/test_io_dispatched.py diff --git a/src/anndata/tests/test_io_elementwise.py b/tests/test_io_elementwise.py similarity index 100% rename from src/anndata/tests/test_io_elementwise.py rename to tests/test_io_elementwise.py diff --git a/src/anndata/tests/test_io_partial.py b/tests/test_io_partial.py similarity index 100% rename from src/anndata/tests/test_io_partial.py rename to tests/test_io_partial.py diff --git a/src/anndata/tests/test_io_utils.py b/tests/test_io_utils.py similarity index 100% rename from src/anndata/tests/test_io_utils.py rename to tests/test_io_utils.py diff --git a/src/anndata/tests/test_io_warnings.py b/tests/test_io_warnings.py similarity index 100% rename from src/anndata/tests/test_io_warnings.py rename to tests/test_io_warnings.py diff --git a/src/anndata/tests/test_layers.py b/tests/test_layers.py similarity index 100% rename from src/anndata/tests/test_layers.py rename to tests/test_layers.py diff --git a/src/anndata/tests/test_obsmvarm.py b/tests/test_obsmvarm.py similarity index 100% rename from src/anndata/tests/test_obsmvarm.py rename to tests/test_obsmvarm.py diff --git a/src/anndata/tests/test_obspvarp.py b/tests/test_obspvarp.py similarity index 100% rename from src/anndata/tests/test_obspvarp.py rename to tests/test_obspvarp.py diff --git a/src/anndata/tests/test_raw.py b/tests/test_raw.py similarity index 100% rename from src/anndata/tests/test_raw.py rename to tests/test_raw.py diff --git a/src/anndata/tests/test_readwrite.py b/tests/test_readwrite.py similarity index 99% rename from src/anndata/tests/test_readwrite.py rename to tests/test_readwrite.py index 0c87eae6e..49a0a48fb 100644 --- a/src/anndata/tests/test_readwrite.py +++ b/tests/test_readwrite.py @@ -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"] diff --git a/src/anndata/tests/test_repr.py b/tests/test_repr.py similarity index 100% rename from src/anndata/tests/test_repr.py rename to tests/test_repr.py diff --git a/src/anndata/tests/test_structured_arrays.py b/tests/test_structured_arrays.py similarity index 100% rename from src/anndata/tests/test_structured_arrays.py rename to tests/test_structured_arrays.py diff --git a/src/anndata/tests/test_transpose.py b/tests/test_transpose.py similarity index 100% rename from src/anndata/tests/test_transpose.py rename to tests/test_transpose.py diff --git a/src/anndata/tests/test_uns.py b/tests/test_uns.py similarity index 100% rename from src/anndata/tests/test_uns.py rename to tests/test_uns.py diff --git a/src/anndata/tests/test_utils.py b/tests/test_utils.py similarity index 100% rename from src/anndata/tests/test_utils.py rename to tests/test_utils.py diff --git a/src/anndata/tests/test_views.py b/tests/test_views.py similarity index 100% rename from src/anndata/tests/test_views.py rename to tests/test_views.py diff --git a/src/anndata/tests/test_x.py b/tests/test_x.py similarity index 100% rename from src/anndata/tests/test_x.py rename to tests/test_x.py