# Special environment for testing?

**URL:** <https://discourse.julialang.org/t/special-environment-for-testing/90306>\
**Category:** General Usage\
**Created:** [November 15, 2022, 5:58pm UTC](https://discourse.julialang.org/t/special-environment-for-testing/90306 "2022-11-15T17:58:35Z")\
**Posts on this page:** 10\
**Page:** 1

<div class="post-metadata">

**Author:** ![PetrKryslUCSD](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/petrkryslucsd/32/215825_2.png) [@PetrKryslUCSD](https://discourse.julialang.org/u/PetrKryslUCSD)\
**Post date:** [November 15, 2022, 5:58pm UTC](https://discourse.julialang.org/t/special-environment-for-testing/90306/1 "2022-11-15T17:58:35Z")

</div>

In order to test a package, I would like to use a test environment which would include many other packages, on which the tested package does _not_ depend. I think it should be possible to have an ad hoc environment in the test folder (is that a thing?), but so far I have not been able to make it work.

Any ideas?

---

<div class="post-metadata">

**Author:** ![sylvaticus](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/sylvaticus/32/203883_2.png) [@sylvaticus](https://discourse.julialang.org/u/sylvaticus)\
**Post date:** [November 15, 2022, 10:01pm UTC](https://discourse.julialang.org/t/special-environment-for-testing/90306/2 "2022-11-15T22:01:27Z")

</div>

Yes, that is the w  
ay it is supposed to work… for example in the test environment I have CSV to load some small dataset, but then the tested package doem\*t depwnds on it…

---

<div class="post-metadata">

**Author:** ![PetrKryslUCSD](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/petrkryslucsd/32/215825_2.png) [@PetrKryslUCSD](https://discourse.julialang.org/u/PetrKryslUCSD)\
**Post date:** [November 15, 2022, 10:17pm UTC](https://discourse.julialang.org/t/special-environment-for-testing/90306/3 "2022-11-15T22:17:42Z")

</div>

Thanks for the confirmation. I think I am now on the right track: I made a project in the `test` folder, and added the packages that I require to that environment. It looks like it might work.

1. Make an environment in the folder `TestedPackage/test`.
2. Add all the packages that are necessary to run the test to that environment.
3. In the folder `TestedPackage` one can now run `]test`.

---

<div class="post-metadata">

**Author:** ![j-fu](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/j-fu/32/11373_2.png) [@j-fu](https://discourse.julialang.org/u/j-fu)\
**Post date:** [November 15, 2022, 10:52pm UTC](https://discourse.julialang.org/t/special-environment-for-testing/90306/4 "2022-11-15T22:52:01Z")

</div>

You can `]test` in the root directory of the package, it automatically uses the test environment.

Update: see the [Pkg documentation](https://pkgdocs.julialang.org/v1/creating-packages/#Test-specific-dependencies-in-Julia-1.2-and-above) on this.

BTW when developing a package `pkgname` I got used to start Julia with `julia --project=@pkgname` which creates an environment in the `.julia/environments` folder (I think since 1.7). This avoids accidental addition of dependecies to the package (which itself needs to be `dev-d` to that environment).  
And you can do `]test pkgname`.

---

<div class="post-metadata">

**Author:** ![PetrKryslUCSD](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/petrkryslucsd/32/215825_2.png) [@PetrKryslUCSD](https://discourse.julialang.org/u/PetrKryslUCSD)\
**Post date:** [November 16, 2022, 5:48pm UTC](https://discourse.julialang.org/t/special-environment-for-testing/90306/5 "2022-11-16T17:48:20Z")

</div>

All: that is a solution, but beware, there’s a catch. The `Manifest.toml` in the test folder  
could interfere with the manifest of the package. I now remove the `Manifest.toml` in the test folder  
before the tests run. The issue was reported a while ago: ["cannot merge projects" error · Issue #1585 · JuliaLang/Pkg.jl · GitHub](https://github.com/JuliaLang/Pkg.jl/issues/1585)

---

<div class="post-metadata">

**Author:** ![TheCedarPrince](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/thecedarprince/32/17323_2.png) [@TheCedarPrince](https://discourse.julialang.org/u/TheCedarPrince)\
**Post date:** [November 16, 2022, 5:51pm UTC](https://discourse.julialang.org/t/special-environment-for-testing/90306/6 "2022-11-16T17:51:10Z")

</div>

@PetrKryslUCSD , not to add to give information overload, but I wrote up a tutorial for this for the Julia docs for the upcoming 1.9 release: [Unit Testing · The Julia Language](https://docs.julialang.org/en/v1.9-dev/stdlib/Test/#Workflow-for-Testing-Packages) I wrote it for my student assistants who were having trouble writing tests – let me know if it could use some improvements!

---

<div class="post-metadata">

**Author:** ![roflmaostc](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/roflmaostc/32/30123_2.png) [@roflmaostc](https://discourse.julialang.org/u/roflmaostc)\
**Post date:** [November 16, 2022, 7:18pm UTC](https://discourse.julialang.org/t/special-environment-for-testing/90306/7 "2022-11-16T19:18:54Z")

</div>

I usually test with the standards tests and [TestEnv.jl](https://github.com/JuliaTesting/TestEnv.jl)

Citing this:

> [@Testing a different file than runtests.jl](https://discourse.julialang.org/t/testing-a-different-file-than-runtests-jl/87789/10):
>
> Just dropping my testing workflow: First, I test everything with (where [TestEnv.jl](https://github.com/JuliaTesting/TestEnv.jl) is installed globally): julia\> using Pkg; Pkg.activate("."); using TestEnv; TestEnv.activate(); include("test/runtests.jl") For any further test runs, I do: julia\> include("test/subtests.jl")

---

<div class="post-metadata">

**Author:** ![PetrKryslUCSD](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/petrkryslucsd/32/215825_2.png) [@PetrKryslUCSD](https://discourse.julialang.org/u/PetrKryslUCSD)\
**Post date:** [November 16, 2022, 9:09pm UTC](https://discourse.julialang.org/t/special-environment-for-testing/90306/8 "2022-11-16T21:09:19Z")

</div>

Does it address the Manifest problem?

---

<div class="post-metadata">

**Author:** ![roflmaostc](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/roflmaostc/32/30123_2.png) [@roflmaostc](https://discourse.julialang.org/u/roflmaostc)\
**Post date:** [November 16, 2022, 9:09pm UTC](https://discourse.julialang.org/t/special-environment-for-testing/90306/9 "2022-11-16T21:09:57Z")

</div>

It creates a temporary manifest each time.

---

<div class="post-metadata">

**Author:** ![PetrKryslUCSD](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/petrkryslucsd/32/215825_2.png) [@PetrKryslUCSD](https://discourse.julialang.org/u/PetrKryslUCSD)\
**Post date:** [November 17, 2022, 2:51am UTC](https://discourse.julialang.org/t/special-environment-for-testing/90306/10 "2022-11-17T02:51:29Z")

</div>

I have to take it back: I do not have a solution at the moment.

The compatibility entry of the `Project.toml` of the test folder is ignored. I get Arpack 0.5.4  
even though my test `Project.toml` clearly states

```julia
[compat]
Arpack = "0.5.3"

```

Arpack 0.5.4 is shot in some as yet obscure way ([eigs() doesn't work in my computer, but works in another one. · Issue #147 · JuliaLinearAlgebra/Arpack.jl · GitHub](https://github.com/JuliaLinearAlgebra/Arpack.jl/issues/147)), which is why I wanted 0.5.3. But: how do I get it if the compatibility section doesn’t work?

Edit: I forgot “= 0.5.3”! Silly me. So the solution described above works.
