I am running into a weird issue. I have some code which I will arbitrarily say is:
z = 10
z += 100
# This code will work, it's just an arbitrary example.
When I have the above code in a random “.jl” file and I run it, there are no issues. However, when I move the code into my “runtests.jl” file and then do
test PkgName, I get an error.
Is there some difference under the hood in the way the code is run usually vs the way it is run when testing a package through the Repl?
There are a couple differences:
Pkg.test spawns a new process to run the tests in, and starts the process with
--startup-file=no (see https://julialang.github.io/Pkg.jl/v1/api/#Pkg.test). I believe on master also Julia will not show deprecation warnings by default (https://github.com/JuliaLang/julia/pull/35362), but
Pkg.test will pass
--depwarn=yes to enable them.
An other difference has to do with dependencies:
Pkg.test will run the tests in an “environment stack” that does not include the “default environment” (I’m actually not sure how to call it; it’s the environment that’s named after the Julia version and which is active by default).
In contrast, the REPL runs by default in a composite environment where the environment of the currently active project is stacked with the default environment, as determined by
"@" # currently active project
"@v#.#" # default environment
"@stdlib" # standard library
This means that if you code makes use of some package that has been
Pkg.added to the default environment, but not declared as a dependency of the current project,
Pkg.test will catch that.
Ah, that reminds me as well that the standard library
InteractiveUtils is loaded automatically in the REPL, but isn’t loaded with
Thanks all! It ended up being that I was using a relative file path and being one folder deeper (in the test folder) messed things up