# LocalPreferences not picked up in test when set globally

**URL:** <https://discourse.julialang.org/t/localpreferences-not-picked-up-in-test-when-set-globally/131748>\
**Category:** Tooling\
**Tags:** question\
**Created:** [August 21, 2025, 8:12am UTC](https://discourse.julialang.org/t/localpreferences-not-picked-up-in-test-when-set-globally/131748 "2025-08-21T08:12:44Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![luraess](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/luraess/32/16189_2.png) [@luraess](https://discourse.julialang.org/u/luraess)\
**Post date:** [August 21, 2025, 8:12am UTC](https://discourse.julialang.org/t/localpreferences-not-picked-up-in-test-when-set-globally/131748/1 "2025-08-21T08:12:44Z")

</div>

Hi,

I am working with various packages such as [Chmy.jl](https://github.com/PTsolvers/Chmy.jl), [JustRelax.jl](https://github.com/PTsolvers/JustRelax.jl), among others, where we support both CPU, GPU and distributed computing backends.

Mostly for GPU backends and MPI support on servers such as HPC clusters and supercomputers, it may be helpful to have a globally set `LocalPreferences.toml` file (and corresponding `Project.toml`) as to set some default preferences such as e.g. using system binaires for MPI or local toolkit for GPU libraries (see e.g. [Configuration · MPI.jl](https://juliaparallel.org/MPI.jl/stable/configuration/#Notes-to-HPC-cluster-administrators)).

Outside of the test environment, all works as expected, i.e., Julia applications pick up the globally set LocalPreferences. However, I realised that running tests using the Julia testing infrastructure `using Pkg; Pkg.test("myPkg")` would pick up local preferences _only_ if a `LocalPreferences.toml` file is present within the repo that is being tested while ignoring the preferences set globally.

As I understand, the Julia load path is changed when running test to the tmp folder tests are run into (e.g. `"JULIA_LOAD_PATH" => "@:/tmp/jl_n7w8ha"`), which overrides the load path set to reading in the global prefs (e.g. `"JULIA_LOAD_PATH" => ":/path/to/global/julia_prefs"`).

Would there be a way to work around this issue and allow the globally set LocalPreferences to be picked up during testing and work as expected in the same fashion as from outside the testing env?

---

<div class="post-metadata">

**Author:** ![cjdoris](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/cjdoris/32/213133_2.png) [@cjdoris](https://discourse.julialang.org/u/cjdoris)\
**Post date:** [August 21, 2025, 9:01am UTC](https://discourse.julialang.org/t/localpreferences-not-picked-up-in-test-when-set-globally/131748/2 "2025-08-21T09:01:08Z")

</div>

Add your global env back into the `LOAD_PATH` within your tests?

---

<div class="post-metadata">

**Author:** ![luraess](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/luraess/32/16189_2.png) [@luraess](https://discourse.julialang.org/u/luraess)\
**Post date:** [August 21, 2025, 9:45am UTC](https://discourse.julialang.org/t/localpreferences-not-picked-up-in-test-when-set-globally/131748/3 "2025-08-21T09:45:47Z")

</div>

Thanks for the suggestion. Unsure tho how to set this up such that it would not interfere with the expected testing configuration.

Also, it would be nice if there could be an approach that would be generic and not having the modify things whether one runs on a system that may have prefs set in a global fashion.

---

<div class="post-metadata">

**Author:** ![cjdoris](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/cjdoris/32/213133_2.png) [@cjdoris](https://discourse.julialang.org/u/cjdoris)\
**Post date:** [August 21, 2025, 10:30am UTC](https://discourse.julialang.org/t/localpreferences-not-picked-up-in-test-when-set-globally/131748/4 "2025-08-21T10:30:25Z")

</div>

Ultimately preferences are loaded by looking through your load path so either:

- you need to add the environment containing your preferences to the load path; or
- you need to add your preferences into one of the environments already in the load path.

I don’t think there’s anything generic to do this for you - AFAIU tests are intentionally run in an isolated environment.

Do you use the implicit test environment (i.e. test dependencies are in the top `Project.toml`) or an explicit one (i.e. you have a `test/Project.toml` file)? Maybe the behaviour is different between these but I doubt it.

---

<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 21, 2025, 10:32am UTC](https://discourse.julialang.org/t/localpreferences-not-picked-up-in-test-when-set-globally/131748/5 "2025-08-21T10:32:42Z")

</div>

It’s a known long-standing issue – Preferences.jl doesn’t actually support global preferences, despite the documentation claiming that it does. See [Global preferences · Issue #33 · JuliaPackaging/Preferences.jl · GitHub](https://github.com/JuliaPackaging/Preferences.jl/issues/33) reported 3.5 years ago.

---

<div class="post-metadata">

**Author:** ![luraess](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/luraess/32/16189_2.png) [@luraess](https://discourse.julialang.org/u/luraess)\
**Post date:** [August 22, 2025, 8:20am UTC](https://discourse.julialang.org/t/localpreferences-not-picked-up-in-test-when-set-globally/131748/6 "2025-08-22T08:20:08Z")

</div>

Thanks for the insights provided which are highly appreciated!

From brief scrolling through Preferences.jl I did not bump on the longer lasting issue, but I feel we’re exactly hitting this.

Outside of `test`, it seems to work fine though to have the globally set LocalPreferences active and those can be overwritten if a `LocalPreferences.toml` file is available in the active project.

Wouldn’t it be possible to propagate this behaviour to testing, Pluto, and others?
