Document what a test item can import - #43
Open
davidanthoff wants to merge 1 commit into
Open
Conversation
The `@testitem` docstring documents `default_imports` and is the only statement of the macro's contract, but it never said what *else* is importable — so the question it most often has to answer, "why can't my test item `using Foo`?", was unanswered here and everywhere else. A test item can import the package's test target and nothing more: its `test/Project.toml`, or its own `[deps]` plus the `[targets]` `test` names resolved through `[extras]`/`[weakdeps]`, plus the package and the standard library. That is one target per package — a `Project.toml` deeper in the tree adds nothing, which is the misunderstanding behind TestItemControllers.jl#97 — and a `@testmodule` or `@testsnippet` is subject to the same limit. Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
The
@testitemdocstring is the only statement of the macro's contract, and it coversdefault_imports— thatusing Testandusing <PackageName>happen automatically — without ever saying what else is importable. So "why can't my test itemusing Foo?" had no answer here, and none anywhere else either.Prompted by TestItemControllers.jl#97, where a user added a dependency to a
Project.tomlnested undertest/and expected the test items beside it to see it.New What a test item can import section: the package's test target and nothing more —
test/Project.tomlif there is one, otherwise the package's own[deps]plus the names its[targets]testlist names via[extras]/[weakdeps]— plus the package itself and the standard library. One target per package, so aProject.tomldeeper in the tree adds nothing; and@testmodule/@testsnippetare subject to the same limit since they are evaluated in the same environment. Names theArgumentError: Package Foo not found in current pathtext so the error is searchable.Docstring only. Suite is 4/4 green.
🤖 Generated with Claude Code