Repository navigation
Description
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 thenssextra. - 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— 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.- 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.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.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.pyimports_save_checkpoint/_load_checkpointat module top and
these import fine withoutnss— 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 realnss.ns.run_nested_samplingcalls"). Check whether those serialization tests pass
once theaf.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.pydocstring states it,test_checkpoint.pyusesimportorskip("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.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
- Installing the
nss/ blackjax-fork extra in the default environment. - Any change to
af.NSSruntime behaviour or the_HAS_NSSimport guard.
Activity
Jammy2211 commentedon Jun 8, 2026
Merged fix in PyAutoFit PR #1312. The default test environment now skips NSS tests that require the optional
nss/ matchingblackjax.nsstack, while retaining pure checkpoint serialization coverage. Local verification before merge: targeted NSS tests4 passed, 13 skipped; full PyAutoFit suite1412 passed, 14 skipped.Jammy2211 commentedon Jul 28, 2026
Closing as complete — swept by an issue-tracker reconciliation pass.
This work shipped and is recorded in PyAutoMind:
PyAutoMind/complete/2026/06/nss-test-optional-dep-skip.mdVerified via two independent legs: the record claims this issue in its
- issue:header, and its pull request is confirmed merged. Reopen if anything here is still outstanding.