Testing private package fails based on dependency

I have a private package that I am trying to test. When I run the test suite, it fails, claiming it can’t find CSV:

ERROR: LoadError: ArgumentError: Package CSV not found in current path:
- Run `import Pkg; Pkg.add("CSV")` to install the CSV 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/doomphoenix/.julia/dev/MoltenSaltThermodynamics/test/runtests.jl:3
ERROR: Package MoltenSaltThermodynamics errored during testing

This despite the fact that CSV is clearly listed as a dependency (in the Project.toml):

[deps]
CSV = "336ed68f-0bac-5ca0-87d4-7b16caf5d00b"
DataFrames = "a93c6f00-e57d-5684-b7b6-d8193f3e46c0"
LaTeXStrings = "b964fa9f-0449-5b57-a5c2-d3ea65f4040f"
LinearAlgebra = "37e2e46d-f89d-539d-b4ee-838fcccc9c8e"
LsqFit = "2fda8390-95c7-5789-9bda-21331edee243"
Plots = "91a5bcdd-55d7-5caf-9e0b-520d859cae80"
Statistics = "10745b16-79ce-11e8-11f9-7d13ad32a3b2"

[compat]
julia = "1"

[extras]
Test = "8dfed614-e22c-5e08-85e1-65c5234f0b40"

[targets]
test = ["Test"]

This does not appear to me to be expected behavior. What am I missing?

I am not the only one who has come across this either, see https://discourse.julialang.org/t/confused-by-pkg-test-behavior/35500.
Thanks!

1 Like

A little more info would be helpful (ideally as a MWE).

Do you have, by any chance, a separate test/Project.toml from which CSV is missing? Cf 5. Creating Packages · Pkg.jl

Sorry to ask, but is has happened to me before: you are using CSV in runtests.jl?

1 Like

I don’t have a separate Project.toml in test, but that is a good thing to keep in mind and something I was unaware of. Yes, I am using CSV in runtests.jl. Judging from the tone of your question, this seems to be the problem, but I’m not sure why that’s the case?

Thanks for the help.

I had exactly the same problem over the weekend, but when I went now to make a little MWE, I found the problem installing CSV had gone away. The problem only happened when you ran Pkg.test(); just running the tests directly from the command line worked fine. Could there have been some corruption problem with the main registry, perhaps?

Graham

1 Like

actually, I still get the error in Travis:

[...]
ERROR: LoadError: LoadError: ArgumentError: Package CSV not found in current path:

- Run `import Pkg; Pkg.add("CSV")` to install the CSV package.

Stacktrace:

 [1] require(::Module, ::Symbol) at ./loading.jl:892

 [2] include(::Module, ::String) at ./Base.jl:377

 [3] include(::String) at /home/travis/build/grahamstark/ScottishTaxBenefitModel.jl/src/ScottishTaxBenefitModel.jl:1

 [4] top-level scope at /home/travis/build/grahamstark/ScottishTaxBenefitModel.jl/src/ScottishTaxBenefitModel.jl:10

 [5] include(::Module, ::String) at ./Base.jl:377

 [6] top-level scope at none:2

 [7] eval at ./boot.jl:331 [inlined]

 [8] eval(::Expr) at ./client.jl:449

 [9] top-level scope at ./none:3

What I had in mind was that you might be calling a CSV function in the tests without using CSV in runtests.jl, but that doesn’t seem to be the problem.

Then I’m afraid it’s hard to figure out the problem without a MWE.

Maybe, the same solution works here: CSV Parsers dependency problem

It might be easier than that: if you don’t have a separate environment for the tests, include all the packages used in runtests.jl in the corresponding target of the package’s Project.toml, for instance:

[targets]
test = ["Test", "CSV", "MoltenSaltThermodynamics"]

Thanks everyone for the help! In the end I was able to solve the problem by creating a specific environment for testing as described in the link that @hendri54 posted. That seems to be the best way of going about this. I didn’t know that Julia had added that capability, but it shows me that I should read the Pkg documentation more carefully!