Skip to content

Canonicalize tests to @safetestset for per-unit module isolation#315

Closed
ChrisRackauckas-Claude wants to merge 1 commit into
SciML:masterfrom
ChrisRackauckas-Claude:canonicalize-safetestset
Closed

Canonicalize tests to @safetestset for per-unit module isolation#315
ChrisRackauckas-Claude wants to merge 1 commit into
SciML:masterfrom
ChrisRackauckas-Claude:canonicalize-safetestset

Conversation

@ChrisRackauckas-Claude

Copy link
Copy Markdown
Contributor

What

Converts each independent test unit in test/runtests.jl from

@testset "X" begin include("x.jl") end

to

@safetestset "X" begin include("x.jl") end

so every unit runs in its own freshly-evaluated module — giving isolation between tests and world-age safety, matching OrdinaryDiffEq's canonical test structure. The outer @testset "DiffEqCallbacks" summary wrapper and the GROUP-dispatch ladder (QA / Core / NoPre), including the Pkg.activate("nopre") / develop / instantiate block, are unchanged.

Self-containment fixes (latent bugs surfaced by isolation)

Two units previously relied on symbols leaking through the shared Main namespace when all files were included into the same module. With per-module isolation these became UndefVarErrors, so the missing dependencies are now made explicit:

  • independentlylinearizedtests.jl used ReturnCode.Default but only imported Test, DiffEqCallbacks; ReturnCode leaked in from a sibling file. Added using SciMLBase: ReturnCode (the same source periodic_tests.jl already imports it from).
  • integrating_GK_sum_tests.jl reused helper functions (compute_dGdp, simple_linear_system, adjoint_linear, adjoint_linear_inplace, analytical_derivative, callback_saving_linear, callback_saving_linear_inplace) that were defined at file scope in integrating_GK_tests.jl and leaked through Main. Those helpers were extracted verbatim into a new test/integrating_GK_shared.jl, and both files now include it.

No assertion logic was changed; the same @test/@test_throws lines run. Nested grouping @testsets inside a unit stay plain @testset (the unit-level @safetestset already isolates).

Deps

Added SafeTestsets to the test dependencies: root [extras] + [targets].test + [compat] SafeTestsets = "0.1, 1", and to test/nopre/Project.toml ([deps] + [compat]) since the NoPre group activates its own environment.

Verification

GROUP=Core Pkg.test() run locally on Julia 1.11: 329 passing, 0 failed, 0 errored (Testing DiffEqCallbacks tests passed). NoPre/QA groups will be exercised by CI.


Ignore until reviewed by @ChrisRackauckas.

🤖 Generated with Claude Code

Convert each independent test unit in runtests.jl from `@testset "X" begin
include("x.jl") end` to `@safetestset "X" begin include("x.jl") end` so that
every unit runs in its own freshly-evaluated module (isolation between tests
plus world-age safety), matching OrdinaryDiffEq's canonical structure. The
outer `@testset "DiffEqCallbacks"` summary wrapper and the GROUP-dispatch
ladder (QA / Core / NoPre) are left unchanged.

Make the now-isolated units self-contained:
- independentlylinearizedtests.jl previously relied on `ReturnCode` leaking
  into shared Main from a sibling file; add `using SciMLBase: ReturnCode`
  (same source periodic_tests.jl already imports it from).
- integrating_GK_sum_tests.jl relied on helper functions defined at file
  scope in integrating_GK_tests.jl leaking through shared Main. Extract those
  shared helpers (compute_dGdp, compute_dGdp_nt, simple_linear_system,
  adjoint_linear[_inplace], analytical_derivative, callback_saving_linear[_inplace])
  verbatim into test/integrating_GK_shared.jl and have both files include it.

Add SafeTestsets to the test deps (root [extras]/[targets].test + [compat],
and test/nopre/Project.toml since the NoPre group activates its own env).

Behavior-preserving: no assertion logic changed; the same @test/@test_throws
run, and the full GROUP=Core suite passes locally (329 passing, 0 fail/error).

Co-Authored-By: Chris Rackauckas <accounts@chrisrackauckas.com>
Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
@ChrisRackauckas-Claude

Copy link
Copy Markdown
Contributor Author

Superseded by the v1.2 folder conversion on sciml-testing-rollout (#316).

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.

2 participants