# Run tests for a package outside ~/.julia/v0.6

**URL:** <https://discourse.julialang.org/t/run-tests-for-a-package-outside-julia-v0-6/5506>\
**Category:** General Usage\
**Tags:** question\
**Created:** [August 22, 2017, 3:17pm UTC](https://discourse.julialang.org/t/run-tests-for-a-package-outside-julia-v0-6/5506 "2017-08-22T15:17:46Z")\
**Posts on this page:** 7\
**Page:** 1

<div class="post-metadata">

**Author:** ![Tamas\_Papp](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/tamas_papp/32/25949_2.png) [@Tamas\_Papp](https://discourse.julialang.org/u/Tamas_Papp)\
**Post date:** [August 22, 2017, 3:17pm UTC](https://discourse.julialang.org/t/run-tests-for-a-package-outside-julia-v0-6/5506/1 "2017-08-22T15:17:46Z")

</div>

I recently reorganized my packages and moved local ones outside `~/.julia/v0.6`. This makes is easier for me to wipe everything when run into problems I can’t solve otherwise.

However, I found that `Pkg.test` does not work any more. Is there a hack/workaround that would allow me to run tests for local packages?

(_I know that I can always symlink things back into `~/.julia/v0.6`, I am interested in other solutions_)

---

<div class="post-metadata">

**Author:** ![Tamas\_Papp](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/tamas_papp/32/25949_2.png) [@Tamas\_Papp](https://discourse.julialang.org/u/Tamas_Papp)\
**Post date:** [August 22, 2017, 3:29pm UTC](https://discourse.julialang.org/t/run-tests-for-a-package-outside-julia-v0-6/5506/2 "2017-08-22T15:29:35Z")

</div>

I looked at `Pkg.test` and now have a partial solution, which just needs a directory. The question is: how can I find the directory for a module? Then I would be all set.

```julia
function local_test(dir; coverage::Bool=false)
    test_path = joinpath(dir, "test", "runtests.jl")
    pkg = splitdir(dir)[2]
    @assert isfile(test_path) "Could not find $(test_path)"
    Base.cd(dir) do
        try
            color = Base.have_color? "--color=yes" : "--color=no"
            codecov = coverage? ["--code-coverage=user"] : ["--code-coverage=none"]
            compilecache = "--compilecache=" * (Bool(Base.JLOptions().use_compilecache) ? "yes" : "no")
            julia_exe = Base.julia_cmd()
            run(`$julia_exe --check-bounds=yes $codecov $color $compilecache $test_path`)
            info("$pkg tests passed")
        catch err
            Base.Pkg.Entry.warnbanner(err, label="[ERROR: $pkg]")
            push!(errs,pkg)
        end
    end
end

```

---

<div class="post-metadata">

**Author:** ![Tamas\_Papp](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/tamas_papp/32/25949_2.png) [@Tamas\_Papp](https://discourse.julialang.org/u/Tamas_Papp)\
**Post date:** [August 22, 2017, 4:02pm UTC](https://discourse.julialang.org/t/run-tests-for-a-package-outside-julia-v0-6/5506/3 "2017-08-22T16:02:58Z")

</div>

This now works, but it makes assumptions about the directory structure which are hopefully standard:

```julia
"""
    local_test(pkgname, [coverage])

Find and test a package in `LOAD_PATH`.
Useful when the package is outside `Pkg.dir()`.
"""
function local_test(pkgname; coverage::Bool=false)
    module_path = Base.find_in_path(pkgname, nothing)
    src_dir, module_file = splitdir(module_path)
    dir = normpath(src_dir, "..")
    test_path = joinpath(dir, "test", "runtests.jl")
    @assert isfile(test_path) "Could not find $(test_path)"
    Base.cd(dir) do
        try
            color = Base.have_color? "--color=yes" : "--color=no"
            codecov = coverage? ["--code-coverage=user"] : ["--code-coverage=none"]
            compilecache = "--compilecache=" * (Bool(Base.JLOptions().use_compilecache) ? "yes" : "no")
            julia_exe = Base.julia_cmd()
            run(`$julia_exe --check-bounds=yes $codecov $color $compilecache $test_path`)
            info("$module_file tests passed")
        catch err
            Base.Pkg.Entry.warnbanner(err, label="[ERROR: $module_file]")
        end
    end
end

```

---

<div class="post-metadata">

**Author:** ![tkoolen](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/tkoolen/32/1603_2.png) [@tkoolen](https://discourse.julialang.org/u/tkoolen)\
**Post date:** [August 22, 2017, 6:31pm UTC](https://discourse.julialang.org/t/run-tests-for-a-package-outside-julia-v0-6/5506/4 "2017-08-22T18:31:37Z")

</div>

Can’t you just [set `JULIA_PKGDIR`](https://docs.julialang.org/en/stable/manual/environment-variables/#JULIA_PKGDIR-1) to point to the new location?

---

<div class="post-metadata">

**Author:** ![Alexander-Barth](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/alexander-barth/32/3692_2.png) [@Alexander-Barth](https://discourse.julialang.org/u/Alexander-Barth)\
**Post date:** [August 22, 2017, 7:12pm UTC](https://discourse.julialang.org/t/run-tests-for-a-package-outside-julia-v0-6/5506/5 "2017-08-22T19:12:19Z")

</div>

Assuming that the module is accessible from `LOAD_PATH`, I am just using something like this when I run the tests locally:

```julia
include("/path/to/MyModule/test/runtest.jl")

```

For code coverage, I rely only on travis-ci.

---

<div class="post-metadata">

**Author:** ![kristoffer.carlsson](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/kristoffer.carlsson/32/22_2.png) [@kristoffer.carlsson](https://discourse.julialang.org/u/kristoffer.carlsson)\
**Post date:** [August 22, 2017, 8:07pm UTC](https://discourse.julialang.org/t/run-tests-for-a-package-outside-julia-v0-6/5506/6 "2017-08-22T20:07:55Z")

</div>

`Pkg.test` has a few convenience like starting the script in a new process so there is no old state hanging around and stuff like segfaults doesn’t kill your main session.

---

<div class="post-metadata">

**Author:** ![Tamas\_Papp](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/tamas_papp/32/25949_2.png) [@Tamas\_Papp](https://discourse.julialang.org/u/Tamas_Papp)\
**Post date:** [August 23, 2017, 7:57am UTC](https://discourse.julialang.org/t/run-tests-for-a-package-outside-julia-v0-6/5506/7 "2017-08-23T07:57:51Z")

</div>

> [@tkoolen](#):
>
> Can’t you just set JULIA\_PKGDIR to point to the new location?

Unfortunately not, `Pkg.test` will complain about the lack of `METADATA`. One could initialize it etc, but that is more hassle than just running the function above.
