Skip to content

feat(test_mode): add with_test_mode_segment helper for path composition#110

Merged
Jammy2211 merged 1 commit into
mainfrom
feature/test-mode-output-path
May 28, 2026
Merged

feat(test_mode): add with_test_mode_segment helper for path composition#110
Jammy2211 merged 1 commit into
mainfrom
feature/test-mode-output-path

Conversation

@Jammy2211
Copy link
Copy Markdown
Collaborator

Summary

Adds autoconf.test_mode.with_test_mode_segment(base) -> Path — a public helper that returns base / "test_mode" when PYAUTO_TEST_MODE is set, else base unchanged. Mirrors the namespacing rule PyAutoFit already applies internally via _test_mode_segment in autofit/non_linear/paths/abstract.py:25.

Why

autolens_workspace and autogalaxy_workspace ship guides/results/aggregator/ tutorials that share an output directory across two processes — a _quick_fit.py helper (writes via a Nautilus search) and data_fitting.py/samples.py/etc. (read via Aggregator.from_directory). The tutorials currently hard-code:

results_path = Path("output") / "results_folder"

Under PYAUTO_TEST_MODE=2 (smoke), the search lands at output/test_mode/results_folder/... while the readers look at output/results_folder/NoneType from mask_header_from and Figure of merit sanity check failed (triage clusters C15 + C2, 6 scripts).

Workspace PRs (linked below once opened) thread this helper through.

Naming choice

with_test_mode_segment — leading word is with_, not test_. This matters because pytest collects every test_* function in test modules as a test (we hit this on the first attempt — pytest tried to run test_mode_output_path with a missing base fixture). The chosen name reads naturally at the callsite:

results_path = with_test_mode_segment(Path("output")) / "results_folder"

Test plan

  • pytest test_autoconf/test_test_mode.py -v — 7/7 pass (env unset, env "0", env "1"/"2"/"3", pathlib chaining).
  • pytest test_autoconf — 102/102 pass, no regressions.

Related PRs

  • autolens_workspace#TBD — thread with_test_mode_segment through _quick_fit.py + 7 aggregator tutorials.
  • autogalaxy_workspace#TBD — same for the autogalaxy mirror.

🤖 Generated with Claude Code

Workspace scripts that compose their own output paths manually (e.g.
autolens_workspace and autogalaxy_workspace `guides/results/aggregator/`
tutorials) need to agree with PyAutoFit's internal `_test_mode_segment`
(`autofit/non_linear/paths/abstract.py`), which inserts
`output/test_mode/...` whenever PYAUTO_TEST_MODE is set.

The internal helper is private; expose the same rule as a public
autoconf helper so workspace scripts can compose

    results_path = with_test_mode_segment(Path("output")) / "results_folder"

…and land in the same directory the search wrote to. For end-users
running with no env vars set, the path stays `output/results_folder/`
unchanged.

Name avoids the `test_` prefix so pytest doesn't try to collect
workspace-script callsites as test functions.

7 unit tests added covering env unset / "0" / "1"/"2"/"3" / chaining
with `/`.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
@Jammy2211 Jammy2211 merged commit ed97fa6 into main May 28, 2026
6 checks passed
@Jammy2211 Jammy2211 deleted the feature/test-mode-output-path branch May 28, 2026 21:04
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant