Error using package in local environment

This is something that has bothered me too. It seems there are two perfectly reasonable ways to structure your test environment:

Have your testing environment defined in the main project.toml file:

MyLibrary
├ Project.toml # this file contains the test environment definition
├ src
│ └ MyLibrary.jl
└ test
   └ runtests.jl

The project file contains extra test information thanks to this section:

[extras]
Test = "8dfed614-e22c-5e08-85e1-65c5234f0b40"
    
[targets]
test = ["Test", "StringViews"]

examples: https://github.com/qojulia/QuantumOptics.jl/blob/master/Project.toml

Or have your test environment as a sub-project

MyLibrary
├ Project.toml # this file does not say anything about tests
├ src
│ └ MyLibrary.jl
└ test
   ├ runtests.jl
   └ Project.toml # this file defines an independent test environment

The two project files do not contain any “extra” fields.

Examples:

By habit and some vague sense of “separation of concerns” I happen to use the second structure. I see some recent discussion of this question here Project.toml in test directory vs extras

I too would like some more authoritative answer in the style of “Use method X because of reason Y”, but I do not have it yet. Perusing the many links in the above discussion would be an interesting archeology expedition through the recent developments in “Julia dev culture”.

Lastly, here is the official documentation that explicitly says there are two ways: https://pkgdocs.julialang.org/dev/creating-packages/#Test-specific-dependencies

I believe your comment about improving the parsing of the Project.toml files during testing is reasonable (including that it would not be breaking compatibility guarantees). I suspect there is no sense of urgency to improve that, while there are a lot of other imperfections of Julia that the core devs consider higher priority. If you have the mental energy to volunteer writing a detailed enhancement suggestion on the bug tracker (and even more so, modify the package import logic and submit a pull request), people might consider it. But that is a lot of volunteer labor with uncertain outcome.

1 Like