I want to be able to run a single test just by including it. For example, imagine the following test file:
using Test, BenchmarkTools
@test 1+1 == 2
If I include it directly, it fails:
include("test/test_example.jl"
ERROR: LoadError: ArgumentError: Package BenchmarkTools not found in current path.
- Run 'import Pkg; Pkg.add("BenchmarkTools")' to install the BenchmarkTools package.
Stacktrace:
Now I modified it:
using Pkg
Pkg.activate(@__DIR__)
using Test, BenchmarkTools
@test 1+1 == 2
And it works:
julia> include("test/test_example.jl")
Activating project at '~/repos/SymbolicAWEModels.jl/test'
Test Passed
But Github Copilot tells me this would be a problematic approach:
`Pkg.activate(@__DIR__)` at top-level will override the temporary test environment that `Pkg.test()` sets up (used in CI via `julia-actions/julia-runtest`). That can change dependency resolution/version selection mid-test run and make CI behavior non-reproducible. Consider activating only when this file is executed directly (e.g., based on `PROGRAM_FILE`), or handle `--project=test` selection in the runner script instead and remove per-file activation during `Pkg.test()` runs.
Is this approach problematic, or can I ignore this warning?
And why is the temporary test environment different from the environment in the test folder?
I use the workspace feature:
[workspace]
projects = ["docs", "examples", "scripts", "test"]
and have a separate Project.toml file in the test folder, which - for example - contains BenchmarkTools.jl.