# \[ANN\] TestEnv.jl: Activate your test enviroment, so you can use your test dependencies

**URL:** <https://discourse.julialang.org/t/ann-testenv-jl-activate-your-test-enviroment-so-you-can-use-your-test-dependencies/65739>\
**Category:** Package Announcements\
**Created:** [August 3, 2021, 10:52am UTC](https://discourse.julialang.org/t/ann-testenv-jl-activate-your-test-enviroment-so-you-can-use-your-test-dependencies/65739 "2021-08-03T10:52:08Z")\
**Posts on this page:** 8\
**Page:** 1

<div class="post-metadata">

**Author:** ![oxinabox](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/oxinabox/32/206603_2.png) [@oxinabox](https://discourse.julialang.org/u/oxinabox)\
**Post date:** [August 3, 2021, 10:52am UTC](https://discourse.julialang.org/t/ann-testenv-jl-activate-your-test-enviroment-so-you-can-use-your-test-dependencies/65739/1 "2021-08-03T10:52:08Z")

</div>

Often when debugging a failing test I want run a snipped of code in the REPL from my tests.  
But often that snippet uses something (like `ChainRulesTestUtil`) which is not a main dependency of my package, just a test dependency.

If using the 1.2 feature that adds seperate test/Project.toml you [can hack around with your LOAD\_PATH to kinda get this to work](https://discourse.julialang.org/t/activating-test-dependencies/48121/7), but that doesn’t work if you use the `[extras]` section of the main Project.toml (which I kinda prefer), and it doesn’t work on 1.0 etc.  
And using the separate test/Project.toml requires you to drop 1.0 support.

**Wouldn’t be nicer if I could just do `TestEnv.activate()`?**  
**and have that work on all julia versions and both ways of setting up your test dependencies ?**

Mal Miller and I have created a package: TestEnv.jl which allows you to do just that.  
Full credit to the Pkg developers for doing the actual hard work to write code for having test environments, that we hacked up to make it possible to activate them.  
We basically cut the sandbox in half, so that it is created but not cleaned up.

This works with all julia versions.  
Though because it accesses internals of Pkg it is very fragile to changes in Pkg – almost ever single minor release of julia breaks this.  
So we have not yet tagged a release off the (currently working) `release-1.8` branch.

My own plan is to add this to my global environment and probably to my startup.jl

> **[GitHub - JuliaTesting/TestEnv.jl: Activate your test enviroment, so you can...](https://github.com/JuliaTesting/TestEnv.jl)**
>
> Activate your test enviroment, so you can use your test dependencies in the REPL - GitHub - JuliaTesting/TestEnv.jl: Activate your test enviroment, so you can use your test dependencies in the REPL

---

<div class="post-metadata">

**Author:** ![Skoffer](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/skoffer/32/378_2.png) [@Skoffer](https://discourse.julialang.org/u/Skoffer)\
**Post date:** [August 3, 2021, 11:05am UTC](https://discourse.julialang.org/t/ann-testenv-jl-activate-your-test-enviroment-so-you-can-use-your-test-dependencies/65739/2 "2021-08-03T11:05:28Z")

</div>

Sorry for naive question, but if (when?) 1.6 is declared as LTS, this package will be less useful, since developers can switch to support 1.6+?

And thank you for development of TestEnv.jl, supporting 1.0 is not so easy now, so it is definitely helpful.

---

<div class="post-metadata">

**Author:** ![oxinabox](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/oxinabox/32/206603_2.png) [@oxinabox](https://discourse.julialang.org/u/oxinabox)\
**Post date:** [August 3, 2021, 11:20am UTC](https://discourse.julialang.org/t/ann-testenv-jl-activate-your-test-enviroment-so-you-can-use-your-test-dependencies/65739/3 "2021-08-03T11:20:09Z")

</div>

> [@Skoffer](#):
>
> Sorry for naive question, but if (when?) 1.6 is declared as LTS, this package will be less useful, since developers can switch to support 1.6+?

Less useful, yes. But still useful.  
For a few reasons:

1. some will keep supporting 1.0 forever (not many but some)
2. some prefer the `[extras]` over the separate Project.toml (I know I do, as otherwise it is too easy to lost track and mistakenly install things both as main and test deps, and potentially with conflicting compat)
3. The way to activate via [hacking on your LOAD\_PATH](https://discourse.julialang.org/t/activating-test-dependencies/48121/7) is kinda undocumented and people run into issues with it. See that [thread](https://discourse.julialang.org/t/activating-test-dependencies/48121/7). TestEnv uses a different mechanism that is basically what `Pkg.test` uses.
4. `TestEnv.activate()` is nicer and easier to write than `push!(Base.LOAD_PATH, joinpath(dirname(Base.active_project()), "test"))`

But yeah, if using the LOAD\_PATH way works for you and you are happy with it, then absolutely no reason to use TestEnv. ✌

---

<div class="post-metadata">

**Author:** ![aplavin](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/aplavin/32/222056_2.png) [@aplavin](https://discourse.julialang.org/u/aplavin)\
**Post date:** [August 3, 2021, 11:23am UTC](https://discourse.julialang.org/t/ann-testenv-jl-activate-your-test-enviroment-so-you-can-use-your-test-dependencies/65739/4 "2021-08-03T11:23:45Z")

</div>

Does `TestEnv` also work in the `test/Project.toml` scenario?

---

<div class="post-metadata">

**Author:** ![oxinabox](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/oxinabox/32/206603_2.png) [@oxinabox](https://discourse.julialang.org/u/oxinabox)\
**Post date:** [August 3, 2021, 11:26am UTC](https://discourse.julialang.org/t/ann-testenv-jl-activate-your-test-enviroment-so-you-can-use-your-test-dependencies/65739/5 "2021-08-03T11:26:47Z")

</div>

> [@aplavin](#):
>
> Does `TestEnv` also work in the `test/Project.toml` scenario?

Yes.

---

<div class="post-metadata">

**Author:** ![oschulz](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/oschulz/32/2998_2.png) [@oschulz](https://discourse.julialang.org/u/oschulz)\
**Post date:** [August 4, 2021, 7:25am UTC](https://discourse.julialang.org/t/ann-testenv-jl-activate-your-test-enviroment-so-you-can-use-your-test-dependencies/65739/6 "2021-08-04T07:25:52Z")

</div>

> [@oxinabox](#):
>
> Wouldn’t be nicer if I could just do `TestEnv.activate()` ?

Thank you so much for this!

---

<div class="post-metadata">

**Author:** ![oschulz](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/oschulz/32/2998_2.png) [@oschulz](https://discourse.julialang.org/u/oschulz)\
**Post date:** [August 4, 2021, 7:27am UTC](https://discourse.julialang.org/t/ann-testenv-jl-activate-your-test-enviroment-so-you-can-use-your-test-dependencies/65739/7 "2021-08-04T07:27:27Z")

</div>

I currently help myself with an ugly shell script that does the `LOAD_PATH` hacking - `TestEnv.activate()` is so much cleaner.

---

<div class="post-metadata">

**Author:** ![oschulz](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/oschulz/32/2998_2.png) [@oschulz](https://discourse.julialang.org/u/oschulz)\
**Post date:** [August 4, 2021, 7:29am UTC](https://discourse.julialang.org/t/ann-testenv-jl-activate-your-test-enviroment-so-you-can-use-your-test-dependencies/65739/8 "2021-08-04T07:29:57Z")

</div>

@davidanthoff would it be possible to support something like this in the VS code Julia plugin, in the environment selector? So that the language server also switches to the test environment?
