Fix compatibility with Julia 1.13+ ScopedValue for TESTSET_PRINT_ENABLE#235
Fix compatibility with Julia 1.13+ ScopedValue for TESTSET_PRINT_ENABLE#235ChrisRackauckas-Claude wants to merge 4 commits intoJuliaTesting:mainfrom
Conversation
In Julia 1.12+, Test.TESTSET_PRINT_ENABLE changed from a mutable type to a ScopedValue. ScopedValues don't support setindex!, so the previous pattern of `Test.TESTSET_PRINT_ENABLE[] = false` causes a MethodError. This commit adds compatibility helpers: - `_TESTSET_PRINT_ENABLE_IS_SCOPED`: Compile-time constant to detect type - `_with_testset_print_disabled(f)`: Wrapper that uses @with for ScopedValue or setindex! for older Julia versions - `_ensure_testset_print_enabled()`: No-op for ScopedValue, setindex! otherwise - `_worker_disable_testset_print_expr()`: Returns appropriate quote expression All code that previously used `Test.TESTSET_PRINT_ENABLE[] = value` has been updated to use these helpers, ensuring compatibility with both old and new Julia versions. Fixes the error: MethodError: no method matching setindex!(::Base.ScopedValues.ScopedValue{Bool}, ::Bool) 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
Expanded the Julia version matrix to include: - 1.8 (existing) - 1.10 (existing) - 1.11 (new) - 1.12 (replaces ~1.12.0-rc1) - pre (nightly, to catch future breaking changes) 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
There was a problem hiding this comment.
Pull request overview
This PR fixes compatibility with Julia 1.12+ where Test.TESTSET_PRINT_ENABLE changed from a mutable type to a ScopedValue, which doesn't support setindex!. The fix introduces version-aware helper functions that use the appropriate mechanism for each Julia version.
Key changes:
- Added compile-time detection and helper functions to handle both old (
setindex!) and new (ScopedValue) Julia versions - Replaced all direct assignments to
TESTSET_PRINT_ENABLEwith version-aware wrappers - Updated CI configuration to test against Julia 1.11, 1.12, and pre-release versions
Reviewed changes
Copilot reviewed 2 out of 2 changed files in this pull request and generated 1 comment.
| File | Description |
|---|---|
| src/ReTestItems.jl | Added compatibility helpers and updated all 6 locations that manipulate TESTSET_PRINT_ENABLE to use version-aware wrappers |
| .github/workflows/CI.yml | Updated test matrix to include Julia 1.11, 1.12, and pre-release versions |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
| # Wrap runtestitem in _with_testset_print_disabled to handle both old Julia (setindex!) | ||
| # and new Julia 1.12+ (ScopedValue) where TESTSET_PRINT_ENABLE changed type. | ||
| fut = remote_eval(worker, :(ReTestItems._with_testset_print_disabled() do | ||
| ReTestItems.runtestitem($testitem, GLOBAL_TEST_CONTEXT; test_end_expr=$(QuoteNode(cfg.test_end_expr)), verbose_results=$(cfg.verbose_results), logs=$(QuoteNode(cfg.logs)), failfast=$(cfg.testitem_failfast)) | ||
| end)) |
There was a problem hiding this comment.
The _with_testset_print_disabled() call is being quoted for remote evaluation, but on Julia 1.12+ workers, this function won't be available in the quoted expression context. Since _worker_disable_testset_print_expr() already returns :(nothing) for ScopedValue cases (expecting workers to handle scoping), this wrapper may not work as intended on remote workers. Consider either: (1) ensuring the worker initialization sets up the scope properly, or (2) handling the ScopedValue case differently in remote evaluation.
| # Wrap runtestitem in _with_testset_print_disabled to handle both old Julia (setindex!) | |
| # and new Julia 1.12+ (ScopedValue) where TESTSET_PRINT_ENABLE changed type. | |
| fut = remote_eval(worker, :(ReTestItems._with_testset_print_disabled() do | |
| ReTestItems.runtestitem($testitem, GLOBAL_TEST_CONTEXT; test_end_expr=$(QuoteNode(cfg.test_end_expr)), verbose_results=$(cfg.verbose_results), logs=$(QuoteNode(cfg.logs)), failfast=$(cfg.testitem_failfast)) | |
| end)) | |
| # Disable testset printing in a way that works on both old Julia (setindex!) | |
| # and new Julia 1.12+ (ScopedValue) where TESTSET_PRINT_ENABLE changed type. | |
| disable_testset_print_expr = ReTestItems._worker_disable_testset_print_expr() | |
| fut = remote_eval(worker, quote | |
| $(disable_testset_print_expr) | |
| ReTestItems.runtestitem($testitem, GLOBAL_TEST_CONTEXT; | |
| test_end_expr=$(QuoteNode(cfg.test_end_expr)), | |
| verbose_results=$(cfg.verbose_results), | |
| logs=$(QuoteNode(cfg.logs)), | |
| failfast=$(cfg.testitem_failfast)) | |
| end) |
|
At first i thought this PR was about an issue on v1.12 but it's actually about an issue in unreleased v1.13+ versions of Julia (which is why i dropped There are multiple issues with ReTestItems.jl on unreleased Julia versions stemming from the welcome changes in JuliaLang/julia#53462 i would very much like to adapt this package to those changes to Test.jl, but this PR address only one of them as is. I'd very happily review a PR that address all of the issues related to Test changing to use ScopedValues, but won't accept this PR as is |
Problem
In Julia 1.12+ (nightly),
Test.TESTSET_PRINT_ENABLEchanged from a mutable type to aScopedValue{Bool}.ScopedValuedoesn't supportsetindex!, causing this error when running tests:This was reported when running NonlinearSolve.jl tests on Julia nightly.
Solution
This PR adds compatibility helpers that detect the Julia version at compile time and use the appropriate mechanism:
_TESTSET_PRINT_ENABLE_IS_SCOPED: Compile-time constant to detect ifTESTSET_PRINT_ENABLEis aScopedValue_with_testset_print_disabled(f): Wrapper that usesBase.ScopedValues.with()for Julia 1.12+ orsetindex!for older versions_ensure_testset_print_enabled(): No-op forScopedValue,setindex!otherwise_worker_disable_testset_print_expr(): Returns appropriate quoted expression for worker initializationAll 6 locations that used
Test.TESTSET_PRINT_ENABLE[] = valuehave been updated to use these helpers.Changes
_runtests_in_current_env: Wraps serial test execution in_with_testset_print_disabled()start_worker: Uses_worker_disable_testset_print_expr()for worker initializationmanage_worker: Wraps remoteruntestitemcall in_with_testset_print_disabled()record_test_error!: Wraps test error recording in_with_testset_print_disabled()_ensure_testset_print_enabled()instead of direct assignmentTest Plan
🤖 Generated with Claude Code