Skip to content

Commit

Permalink
Upload scrublet scores on test failure (#3069)
Browse files Browse the repository at this point in the history
Co-authored-by: Phil Schaf <[email protected]>
  • Loading branch information
ilan-gold and flying-sheep authored Sep 19, 2024
1 parent 303404a commit bd75839
Show file tree
Hide file tree
Showing 3 changed files with 35 additions and 9 deletions.
6 changes: 6 additions & 0 deletions .azure-pipelines.yml
Original file line number Diff line number Diff line change
Expand Up @@ -103,6 +103,12 @@ jobs:
testResultsFormat: NUnit
testRunTitle: 'Publish test results for $(Agent.JobName)'

- task: PublishBuildArtifacts@1
inputs:
pathToPublish: '.pytest_cache/d/debug'
artifactName: debug-data
condition: eq(variables['TEST_TYPE'], 'coverage')

- script: bash <(curl -s https://codecov.io/bash)
displayName: 'Upload to codecov.io'
condition: eq(variables['TEST_TYPE'], 'coverage')
Expand Down
2 changes: 2 additions & 0 deletions src/testing/scanpy/_pytest/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,8 @@ def _global_test_context(
sc.settings.logfile = sys.stderr
sc.settings.verbosity = "hint"
sc.settings.autoshow = True
# create directory for debug data
cache.mkdir("debug")
# reuse data files between test runs (unless overwritten in the test)
sc.settings.datasetdir = cache.mkdir("scanpy-data")
# create new writedir for each test run
Expand Down
36 changes: 27 additions & 9 deletions tests/test_scrublet.py
Original file line number Diff line number Diff line change
Expand Up @@ -117,7 +117,7 @@ def _create_sim_from_parents(adata: AnnData, parents: np.ndarray) -> AnnData:
)


def test_scrublet_data():
def test_scrublet_data(cache: pytest.Cache):
"""
Test that Scrublet processing is arranged correctly.
Expand Down Expand Up @@ -156,14 +156,32 @@ def test_scrublet_data():
random_state=random_state,
)

# Require that the doublet scores are the same whether simulation is via
# the main function or manually provided
assert_allclose(
adata_scrublet_manual_sim.obs["doublet_score"],
adata_scrublet_auto_sim.obs["doublet_score"],
atol=1e-15,
rtol=1e-15,
)
try:
# Require that the doublet scores are the same whether simulation is via
# the main function or manually provided
assert_allclose(
adata_scrublet_manual_sim.obs["doublet_score"],
adata_scrublet_auto_sim.obs["doublet_score"],
atol=1e-15,
rtol=1e-15,
)
except AssertionError:
import zarr

# try debugging https://github.com/scverse/scanpy/issues/3068
cache_path = cache.mkdir("debug")
store_manual = zarr.ZipStore(cache_path / "scrublet-manual.zip", mode="w")
store_auto = zarr.ZipStore(cache_path / "scrublet-auto.zip", mode="w")
z_manual = zarr.zeros(
adata_scrublet_manual_sim.shape[0], chunks=10, store=store_manual
)
z_auto = zarr.zeros(
adata_scrublet_auto_sim.shape[0], chunks=10, store=store_auto
)
z_manual[...] = adata_scrublet_manual_sim.obs["doublet_score"].values
z_auto[...] = adata_scrublet_auto_sim.obs["doublet_score"].values

raise


@pytest.fixture(scope="module")
Expand Down

0 comments on commit bd75839

Please sign in to comment.