# Is there a difference under the hood between running code via a .jl file and running code via \`test name\_of\_pkg\`?

**URL:** <https://discourse.julialang.org/t/is-there-a-difference-under-the-hood-between-running-code-via-a-jl-file-and-running-code-via-test-name-of-pkg/38097>\
**Category:** General Usage\
**Tags:** question\
**Created:** [April 23, 2020, 4:28pm UTC](https://discourse.julialang.org/t/is-there-a-difference-under-the-hood-between-running-code-via-a-jl-file-and-running-code-via-test-name-of-pkg/38097 "2020-04-23T16:28:08Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![logankilpatrick](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/logankilpatrick/32/38123_2.png) [@logankilpatrick](https://discourse.julialang.org/u/logankilpatrick)\
**Post date:** [April 23, 2020, 4:28pm UTC](https://discourse.julialang.org/t/is-there-a-difference-under-the-hood-between-running-code-via-a-jl-file-and-running-code-via-test-name-of-pkg/38097/1 "2020-04-23T16:28:08Z")

</div>

Hey all,

I am running into a weird issue. I have some code which I will arbitrarily say is:

```julia
function z()
   z = 10
   z += 100
end
z()
# 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?**

---

<div class="post-metadata">

**Author:** ![ericphanson](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/ericphanson/32/215186_2.png) [@ericphanson](https://discourse.julialang.org/u/ericphanson)\
**Post date:** [April 23, 2020, 4:39pm UTC](https://discourse.julialang.org/t/is-there-a-difference-under-the-hood-between-running-code-via-a-jl-file-and-running-code-via-test-name-of-pkg/38097/2 "2020-04-23T16:39:23Z")

</div>

There are a couple differences: `Pkg.test` spawns a new process to run the tests in, and starts the process with `--check-bounds=yes` and `--startup-file=no` (see [12. API Reference · Pkg.jl](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](https://github.com/JuliaLang/julia/pull/35362)), but `Pkg.test` will pass `--depwarn=yes` to enable them.

---

<div class="post-metadata">

**Author:** ![ffevotte](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/ffevotte/32/6587_2.png) [@ffevotte](https://discourse.julialang.org/u/ffevotte)\
**Post date:** [April 23, 2020, 7:36pm UTC](https://discourse.julialang.org/t/is-there-a-difference-under-the-hood-between-running-code-via-a-jl-file-and-running-code-via-test-name-of-pkg/38097/3 "2020-04-23T19:36:40Z")

</div>

An other difference has to do with dependencies: `Pkg.test` will run the tests in an [“environment stack”](https://docs.julialang.org/en/v1/manual/code-loading/#Environment-stacks-1) 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 [`LOAD_PATH`](https://docs.julialang.org/en/v1/base/constants/#Base.LOAD_PATH):

```julia
julia> LOAD_PATH
3-element Array{String,1}:
 "@" # currently active project
 "@v#.#" # default environment
 "@stdlib" # standard library

```

This means that if you code makes use of some package that has been `Pkg.add`ed to the default environment, but not declared as a dependency of the current project, `Pkg.test` will catch that.

---

<div class="post-metadata">

**Author:** ![ericphanson](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/ericphanson/32/215186_2.png) [@ericphanson](https://discourse.julialang.org/u/ericphanson)\
**Post date:** [April 23, 2020, 7:52pm UTC](https://discourse.julialang.org/t/is-there-a-difference-under-the-hood-between-running-code-via-a-jl-file-and-running-code-via-test-name-of-pkg/38097/4 "2020-04-23T19:52:39Z")

</div>

Ah, that reminds me as well that the standard library `InteractiveUtils` is loaded automatically in the REPL, but isn’t loaded with `Pkg.test`.

---

<div class="post-metadata">

**Author:** ![logankilpatrick](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/logankilpatrick/32/38123_2.png) [@logankilpatrick](https://discourse.julialang.org/u/logankilpatrick)\
**Post date:** [April 24, 2020, 12:28am UTC](https://discourse.julialang.org/t/is-there-a-difference-under-the-hood-between-running-code-via-a-jl-file-and-running-code-via-test-name-of-pkg/38097/5 "2020-04-24T00:28:19Z")

</div>

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 🙂
