Installing dependencies for separate Project.toml during package development/testing

Marginal note: you could avoid the activate part using the --project command-line switch:

julia --project=examples -e 'import Pkg; Pkg.instantiate(); include("examples/example1.jl")'

Apart from that, this looks more or less like what I do (but let’s see if others have better ideas to suggest!)

Note that this works fine if the project defined in examples/Project.toml knows about its “parent project” A. In your case, maybe you used Pkg.dev to add project A as a dependency of project examples?


I’m not sure about all the details, but Pkg.test() involves spawning a new julia process with additional command-line flags (like --check-bounds=yes) in order to make sure your tests run in a clean and “hardened” environment so that you can catch as many errors as possible. You might not want all of that when running your examples.

Also, Pkg.test() somehow merges the main environment (defined by project A) with the testing environment (defined by test/Project.toml). This makes it possible for your tests to refer to project A without explicitly Pkg.developing it in the testing environment. I might not be up to speed on this topic, but last time I checked there were discussions about allowing such super-project / sub-project relations in broader contexts than just tests.

2 Likes