Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Julia Can't Test User Packages

Tags:

julia

I have a Julia package I developed locally, let's call it mypack, and I can't automatically test it with Julia in pkg mode. Running pkg>test mypack gives me the following error:

(v1.3) pkg> test mypack
  Updating registry at `~/.julia/environments/v1.3/registries/General`
  Updating git-repo `https://github.com/JuliaRegistries/General.git`
   Testing mypack
 Resolving package versions...
[ Info: No changes
    Status `/tmp/jl_m6URie/Manifest.toml`
  [4e168b6d] mypack v0.1.0 [`~/Documents/mypack`]
ERROR: LoadError: ArgumentError: Package Test not found in current path:
- Run `import Pkg; Pkg.add("Test")` to install the Test package.

Stacktrace:
 [1] require(::Module, ::Symbol) at ./loading.jl:887
 [2] include at ./boot.jl:328 [inlined]
 [3] include_relative(::Module, ::String) at ./loading.jl:1105
 [4] include(::Module, ::String) at ./Base.jl:31
 [5] include(::String) at ./client.jl:424
 [6] top-level scope at none:6
in expression starting at /home/myname/Documents/mypack/test/runtests.jl:1
ERROR: Package mypack errored during testing

My mypack project has the expected structure where there's a root directory with a Project.toml and Manifest.toml generated using ]generate mypack. /test/runtests.jl is just the line

using Test

This works on two machines that I've tested it on, one of which was using Julia 1.1 and one which was using Julia 1.2. The errors are happening on a new install of Julia 1.3.

I am able to test other packages (such as Statistics just fine, which I did to make sure Test was working). I have a more complicated project which brought this to my attention, but this mypack MWE is also broken.

like image 261
QtizedQ Avatar asked Mar 12 '20 20:03

QtizedQ


People also ask

How do you run a test in Julia?

Testing Base JuliaIf you build Julia from source, you can run this test suite with make test . In a binary install, you can run the test suite using Base. runtests() . Run the Julia unit tests listed in tests , which can be either a string or an array of strings, using ncores processors.

How many packages does Julia have?

The Julia ecosystem contains over 7,400 packages that are registered in the General registry, which means that finding the right package can be a challenge.

How do I open package manager in Julia?

Enter the Pkg REPL by pressing ] from the Julia REPL. To get back to the Julia REPL, press backspace or ^C. This guide relies on the Pkg REPL to execute Pkg commands.


1 Answers

When you run Pkg.test, Pkg creates a test environment. This environment consists of direct dependencies and test dependencies. Any dependency which is imported by test/runtests.jl needs to be in this test environment.

Because your test/runtests.jl imports the Test standard library, you need to add it as a test dependency. You can add test dependencies using this method: https://julialang.github.io/Pkg.jl/v1/creating-packages/#Test-specific-dependencies-in-Julia-1.0-and-1.1-1.

like image 93
David Varela Avatar answered Oct 20 '22 00:10

David Varela