Overview
13 tests under test_autofit/non_linear/search/nest/nss/ fail in any environment without the
optional nss / handley-lab/blackjax extra installed. They guard on JAX
(pytest.importorskip("jax")) but not on the nss package, so af.NSS.__init__ raises
ImportError at instantiation instead of the tests skipping. This is a test-hygiene gap, not a
code regression (confirmed reproducible with no relevant local changes). The fix adds a skip
guard mirroring the existing JAX one.
Plan
- Add an optional-dependency skip guard to the two nss test files, mirroring
importorskip("jax").
- Prefer a surgical guard: only skip tests that instantiate
af.NSS; keep the pure
checkpoint-serialization round-trip tests running if they work without the nss extra.
- Verify
test_autofit/ reports 0 failures (13 -> skipped) without the extra, and still passes with it.
Detailed implementation plan
Affected Repositories
- rhayes777/PyAutoFit (primary, test-only)
Work Classification
Library (test-only)
Branch Survey
| Repository |
Current Branch |
Dirty? |
| ./PyAutoFit (canonical) |
feature/latent-nan-masking-fix |
dirty (unregistered) |
| PyAutoFit (worktree) |
feature/analysis-shared-state |
held by analysis-shared-state |
Suggested branch: feature/nss-test-optional-dep-skip
Worktree root: ~/Code/PyAutoLabs-wt/nss-test-optional-dep-skip/
Implementation Steps
test_autofit/.../nss/test_search.py — add pytest.importorskip for the nss package (or skipif(not _HAS_NSS)) at module top.
test_autofit/.../nss/test_checkpoint.py — same; but first check whether the _save_checkpoint/_load_checkpoint serialization tests pass without nss (they import fine) and keep those running if so — only guard the af.NSS-instantiating tests.
- Run full
test_autofit/ without the [nss] extra -> confirm 13 become skips, 0 failures.
Key Files
test_autofit/non_linear/search/nest/nss/test_search.py
test_autofit/non_linear/search/nest/nss/test_checkpoint.py
autofit/non_linear/search/nest/nss/search.py (reference only — _HAS_NSS flag; do not change the guard)
Original Prompt
Click to expand starting prompt
Skip af.NSS unit tests when the optional nss dependency is absent
Primary repo: @PyAutoFit (test-only change).
Problem
13 tests under test_autofit/non_linear/search/nest/nss/ fail on a clean checkout of
main in any environment that does not have the optional nss extra installed:
test_autofit/non_linear/search/nest/nss/test_checkpoint.py (4 failures)
test_autofit/non_linear/search/nest/nss/test_search.py (9 failures)
All 13 share one root cause (confirmed by reproducing on clean main, no local changes):
ImportError: af.NSS requires the optional `nss` package and the matching
`handley-lab/blackjax` fork. Install via:
pip install autofit[nss]
raised at autofit/non_linear/search/nest/nss/search.py:254 inside af.NSS.__init__
(guarded by the module's _HAS_NSS flag).
This is not a code regression — it is a test-hygiene gap. The tests guard on JAX being
present (jax = pytest.importorskip("jax") at the top of test_checkpoint.py) but do not
guard on the nss optional dependency. So on a machine with jax but without the [nss]
extra (the default dev/CI environment here), every test that constructs af.NSS hard-fails
at import/instantiation instead of skipping.
Fix (resolve in the issue — confirm the surgical vs blanket choice)
Add a skip guard for the optional nss dependency, mirroring the existing
pytest.importorskip("jax") pattern. Options:
-
Module-level skip on both files:
from autofit.non_linear.search.nest.nss.search import _HAS_NSS
pytestmark = pytest.mark.skipif(not _HAS_NSS, reason="requires optional `nss` extra")
(or pytest.importorskip("nss") / the blackjax-fork module at module top).
-
Surgical: only guard the tests that actually instantiate af.NSS. Note that
test_checkpoint.py imports _save_checkpoint / _load_checkpoint at module top and
these import fine without nss — so the pure-serialization round-trip tests may be able
to run without the extra (they use synthetic pytree states, per the file's docstring:
"No real nss.ns.run_nested_sampling calls"). Check whether those serialization tests pass
once the af.NSS-instantiating tests are skipped; if so, prefer keeping them running and
only skip the instantiation/config tests.
Decide between (1) and (2) in the issue. Favour (2) if the serialization helpers genuinely
work without nss — it keeps real coverage on this machine; fall back to (1) if they don't.
Constraints / context
- Library policy: no JAX in library unit tests — these files already respect that
(test_search.py docstring states it, test_checkpoint.py uses importorskip("jax")).
The fix must not introduce a hard JAX/nss import at collection time.
- The heavy end-to-end nss runs live in
autolens_workspace_developer/searches_minimal/nss_*.py (per the test docstrings) — out of
scope here.
- Verify the fix against the full
test_autofit/ run: after the change, test_autofit/
should report 0 failures in an environment without the [nss] extra (the 13 become
skips), and still pass when the extra IS installed.
Critical files
test_autofit/non_linear/search/nest/nss/test_checkpoint.py
test_autofit/non_linear/search/nest/nss/test_search.py
autofit/non_linear/search/nest/nss/search.py (reference: _HAS_NSS flag + the
__init__ ImportError guard — do not change the guard itself)
Out of scope
- Installing the
nss / blackjax-fork extra in the default environment.
- Any change to
af.NSS runtime behaviour or the _HAS_NSS import guard.
Overview
13 tests under
test_autofit/non_linear/search/nest/nss/fail in any environment without theoptional
nss/handley-lab/blackjaxextra installed. They guard on JAX(
pytest.importorskip("jax")) but not on thensspackage, soaf.NSS.__init__raisesImportErrorat instantiation instead of the tests skipping. This is a test-hygiene gap, not acode regression (confirmed reproducible with no relevant local changes). The fix adds a skip
guard mirroring the existing JAX one.
Plan
importorskip("jax").af.NSS; keep the purecheckpoint-serialization round-trip tests running if they work without the
nssextra.test_autofit/reports 0 failures (13 -> skipped) without the extra, and still passes with it.Detailed implementation plan
Affected Repositories
Work Classification
Library (test-only)
Branch Survey
Suggested branch:
feature/nss-test-optional-dep-skipWorktree root:
~/Code/PyAutoLabs-wt/nss-test-optional-dep-skip/Implementation Steps
test_autofit/.../nss/test_search.py— addpytest.importorskipfor the nss package (orskipif(not _HAS_NSS)) at module top.test_autofit/.../nss/test_checkpoint.py— same; but first check whether the_save_checkpoint/_load_checkpointserialization tests pass withoutnss(they import fine) and keep those running if so — only guard theaf.NSS-instantiating tests.test_autofit/without the[nss]extra -> confirm 13 become skips, 0 failures.Key Files
test_autofit/non_linear/search/nest/nss/test_search.pytest_autofit/non_linear/search/nest/nss/test_checkpoint.pyautofit/non_linear/search/nest/nss/search.py(reference only —_HAS_NSSflag; do not change the guard)Original Prompt
Click to expand starting prompt
Skip
af.NSSunit tests when the optionalnssdependency is absentPrimary repo: @PyAutoFit (test-only change).
Problem
13 tests under
test_autofit/non_linear/search/nest/nss/fail on a clean checkout ofmainin any environment that does not have the optionalnssextra installed:All 13 share one root cause (confirmed by reproducing on clean
main, no local changes):raised at
autofit/non_linear/search/nest/nss/search.py:254insideaf.NSS.__init__(guarded by the module's
_HAS_NSSflag).This is not a code regression — it is a test-hygiene gap. The tests guard on JAX being
present (
jax = pytest.importorskip("jax")at the top oftest_checkpoint.py) but do notguard on the
nssoptional dependency. So on a machine withjaxbut without the[nss]extra (the default dev/CI environment here), every test that constructs
af.NSShard-failsat import/instantiation instead of skipping.
Fix (resolve in the issue — confirm the surgical vs blanket choice)
Add a skip guard for the optional
nssdependency, mirroring the existingpytest.importorskip("jax")pattern. Options:Module-level skip on both files:
(or
pytest.importorskip("nss")/ the blackjax-fork module at module top).Surgical: only guard the tests that actually instantiate
af.NSS. Note thattest_checkpoint.pyimports_save_checkpoint/_load_checkpointat module top andthese import fine without
nss— so the pure-serialization round-trip tests may be ableto run without the extra (they use synthetic pytree states, per the file's docstring:
"No real
nss.ns.run_nested_samplingcalls"). Check whether those serialization tests passonce the
af.NSS-instantiating tests are skipped; if so, prefer keeping them running andonly skip the instantiation/config tests.
Decide between (1) and (2) in the issue. Favour (2) if the serialization helpers genuinely
work without
nss— it keeps real coverage on this machine; fall back to (1) if they don't.Constraints / context
(
test_search.pydocstring states it,test_checkpoint.pyusesimportorskip("jax")).The fix must not introduce a hard JAX/nss import at collection time.
autolens_workspace_developer/searches_minimal/nss_*.py(per the test docstrings) — out ofscope here.
test_autofit/run: after the change,test_autofit/should report 0 failures in an environment without the
[nss]extra (the 13 becomeskips), and still pass when the extra IS installed.
Critical files
test_autofit/non_linear/search/nest/nss/test_checkpoint.pytest_autofit/non_linear/search/nest/nss/test_search.pyautofit/non_linear/search/nest/nss/search.py(reference:_HAS_NSSflag + the__init__ImportError guard — do not change the guard itself)Out of scope
nss/ blackjax-fork extra in the default environment.af.NSSruntime behaviour or the_HAS_NSSimport guard.