# Error using package in local environment

**URL:** <https://discourse.julialang.org/t/error-using-package-in-local-environment/91777>\
**Category:** General Usage\
**Tags:** testing, configuration\
**Created:** [December 17, 2022, 2:12pm UTC](https://discourse.julialang.org/t/error-using-package-in-local-environment/91777 "2022-12-17T14:12:41Z")\
**Posts on this page:** 1\
**Showing post:** 15

<div class="post-metadata">

**Author:** ![Krastanov](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/krastanov/32/6817_2.png) [@Krastanov](https://discourse.julialang.org/u/Krastanov)\
**Post date:** [December 18, 2022, 12:38am UTC](https://discourse.julialang.org/t/error-using-package-in-local-environment/91777/15 "2022-12-18T00:38:41Z")

</div>

> [@mmv](#):
>
> BTW, should there be only one `Project.toml` file in the main directory of a project? Somehow, I saw one popping up in the `test` subdirectory, though I don’t know why or how that came about… And where can I find a detailed documentation about what to include in a `Project.toml` file (earlier question)?

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:

```julia-auto
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:

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

```

examples: [QuantumOptics.jl/Project.toml at master · qojulia/QuantumOptics.jl · GitHub](https://github.com/qojulia/QuantumOptics.jl/blob/master/Project.toml)

## Or have your test environment as a sub-project

```julia-auto
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:

- the main file [QuantumClifford.jl/Project.toml at master · QuantumSavory/QuantumClifford.jl · GitHub](https://github.com/Krastanov/QuantumClifford.jl/blob/master/Project.toml)
- the test file [QuantumClifford.jl/test/Project.toml at master · QuantumSavory/QuantumClifford.jl · GitHub](https://github.com/Krastanov/QuantumClifford.jl/blob/master/test/Project.toml)

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](https://discourse.julialang.org/t/project-toml-in-test-directory-vs-extras/59199)

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: [5. Creating Packages · Pkg.jl](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.

---

_[View the full topic](https://discourse.julialang.org/t/error-using-package-in-local-environment/91777)._
