Skip to content

Conversation

@ChrisRackauckas-Claude
Copy link

Problem

In Julia 1.12+ (nightly), Test.TESTSET_PRINT_ENABLE changed from a mutable type to a ScopedValue{Bool}. ScopedValue doesn't support setindex!, causing this error when running tests:

MethodError: no method matching setindex!(::Base.ScopedValues.ScopedValue{Bool}, ::Bool)
The function `setindex!` exists, but no method is defined for this combination of argument types.

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:

  1. _TESTSET_PRINT_ENABLE_IS_SCOPED: Compile-time constant to detect if TESTSET_PRINT_ENABLE is a ScopedValue
  2. _with_testset_print_disabled(f): Wrapper that uses Base.ScopedValues.with() for Julia 1.12+ or setindex! for older versions
  3. _ensure_testset_print_enabled(): No-op for ScopedValue, setindex! otherwise
  4. _worker_disable_testset_print_expr(): Returns appropriate quoted expression for worker initialization

All 6 locations that used Test.TESTSET_PRINT_ENABLE[] = value have 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 initialization
  • manage_worker: Wraps remote runtestitem call in _with_testset_print_disabled()
  • record_test_error!: Wraps test error recording in _with_testset_print_disabled()
  • Post-test cleanup uses _ensure_testset_print_enabled() instead of direct assignment

Test Plan

  • Verify tests pass on Julia 1.10, 1.11 (existing behavior preserved)
  • Verify tests pass on Julia nightly/1.12 (new ScopedValue compatibility)

🤖 Generated with Claude Code

ChrisRackauckas and others added 2 commits December 18, 2025 03:51
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>
Copy link

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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_ENABLE with 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.

Comment on lines +709 to +713
# 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))
Copy link

Copilot AI Dec 18, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Suggested change
# 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)

Copilot uses AI. Check for mistakes.
@nickrobinson251 nickrobinson251 self-requested a review December 18, 2025 11:12
@nickrobinson251
Copy link
Member

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 pre from the CI list this PR added)

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

Copy link
Member

@nickrobinson251 nickrobinson251 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

would need to address multiple other changes related to Test.jl using ScopedValues to get this package working with v1.13+

(note the PR description is wrong, the ScopedValues change is not in v1.12)

@nickrobinson251 nickrobinson251 changed the title Fix compatibility with Julia 1.12+ ScopedValue for TESTSET_PRINT_ENABLE Fix compatibility with Julia 1.13+ ScopedValue for TESTSET_PRINT_ENABLE Dec 18, 2025
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.

3 participants