How do I activate the test environment of a package?

I want to do some testing of changes to a package I’ve deved. I activate the package environment, but it doesn’t have some imported packages I want to use during testing. (For concreteness, I’m working on ModelingToolkit and I want to use OrdinaryDiffEq.) Now, I see that there’s a test target in the package’s Project.toml which includes OrdinaryDiffEq.

I tried activate test but I got:

(ModelingToolkit) pkg> activate test
  Activating new project at `C:\Users\lucas\Documents\Code\Jdev\ModelingToolkit\test`

which is not what I intended. What should I be doing instead? I don’t think I should be adding OrdinaryDiffEq to the base environment of ModelingToolkit here. (First of all, it’s not meant to be a dependency, and second, IDK if I’ll get the right version number.)

Try GitHub - JuliaTesting/TestEnv.jl: Activate your test enviroment, so you can use your test dependencies in the REPL

Not perfect (because you need one more package), but works for me…

1 Like

My workaround is to

  1. activate the test environment,

  2. put .. in LOAD_PATH.

I have utility functions for this in my startup file. It is kind of a hack, but it works.

function put_in_load_path!(dir = "..", pos = 2)
    if dir ∈ LOAD_PATH
        @warn "$(dir) is already in LOAD_PATH"
        insert!(LOAD_PATH, pos, dir)

function del_in_load_path!(dir = "..")
    pos = findfirst(isequal(dir), LOAD_PATH)
    if pos ≡ nothing
        @warn "$(dir) is not in LOAD_PATH"
        deleteat!(LOAD_PATH, pos)

Yup, this is the winner for sure, and doesn’t require any non-dev tool packages in your global environment. How to use VSCode and REPL to write and test a package? - #4 by jlperla writes up what I found to be the easiest workflow. If a package doesn’t have a test/Project.toml but has it embedded in the main Project file, I think TestEnv is still supposed to work.

1 Like

Yes, it works for both cases