# Run Pkg.test but not in a separate process

**URL:** <https://discourse.julialang.org/t/run-pkg-test-but-not-in-a-separate-process/103176>\
**Category:** Tooling\
**Created:** [August 25, 2023, 6:47am UTC](https://discourse.julialang.org/t/run-pkg-test-but-not-in-a-separate-process/103176 "2023-08-25T06:47:21Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![kellertuer](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/kellertuer/32/220707_2.png) [@kellertuer](https://discourse.julialang.org/u/kellertuer)\
**Post date:** [August 25, 2023, 6:47am UTC](https://discourse.julialang.org/t/run-pkg-test-but-not-in-a-separate-process/103176/1 "2023-08-25T06:47:21Z")

</div>

I would like to have a script that runs my test with a few different settings (basically `ENV` variables). For that I would like to use `Pkg.test` (instead of the `] test MyPackage` which might be a bit manual for this). However, I would prefer the test to run (a) in the test environment for sure but (b) in the same process as my main script (that is just easier to cancel) – is there a way to issue `Pkg.test` such that is does not spawn a new process but merely activates the test environment before running? That would be great.

---

<div class="post-metadata">

**Author:** ![maleadt](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/maleadt/32/10097_2.png) [@maleadt](https://discourse.julialang.org/u/maleadt)\
**Post date:** [August 25, 2023, 7:13am UTC](https://discourse.julialang.org/t/run-pkg-test-but-not-in-a-separate-process/103176/2 "2023-08-25T07:13:36Z")

</div>

I don’t think Pkg has an option like that. You could use TestEnv.jl to activate the test environment, and replicate what `Pkg.test` does (`--check-bounds=yes`, include `runtests.jl`, etc; see [https://github.com/JuliaLang/Pkg.jl/blob/047734e4c7e2b5e99622b4803ec4ad0d49f1d1d3/src/Operations.jl#L1642-L1696](https://github.com/JuliaLang/Pkg.jl/blob/047734e4c7e2b5e99622b4803ec4ad0d49f1d1d3/src/Operations.jl#L1642-L1696)).

---

<div class="post-metadata">

**Author:** ![kellertuer](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/kellertuer/32/220707_2.png) [@kellertuer](https://discourse.julialang.org/u/kellertuer)\
**Post date:** [August 25, 2023, 8:26am UTC](https://discourse.julialang.org/t/run-pkg-test-but-not-in-a-separate-process/103176/3 "2023-08-25T08:26:43Z")

</div>

`TestEnv` sounds like a very good idea. The main thing I was missing (when running `runtests` myself) was the environment.
