Skip to content

Document what a test item can import - #43

Open
davidanthoff wants to merge 1 commit into
mainfrom
docs/what-is-importable
Open

Document what a test item can import#43
davidanthoff wants to merge 1 commit into
mainfrom
docs/what-is-importable

Conversation

@davidanthoff

Copy link
Copy Markdown
Member

The @testitem docstring is the only statement of the macro's contract, and it covers default_imports — that using Test and using <PackageName> happen automatically — without ever saying what else is importable. So "why can't my test item using Foo?" had no answer here, and none anywhere else either.

Prompted by TestItemControllers.jl#97, where a user added a dependency to a Project.toml nested under test/ 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.toml if there is one, otherwise the package's own [deps] plus the names its [targets] test list names via [extras]/[weakdeps] — plus the package itself and the standard library. One target per package, so a Project.toml deeper in the tree adds nothing; and @testmodule/@testsnippet are subject to the same limit since they are evaluated in the same environment. Names the ArgumentError: Package Foo not found in current path text so the error is searchable.

Docstring only. Suite is 4/4 green.

🤖 Generated with Claude Code

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>
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