I am trying to write a test module for a package I am developing. However it looks like I don’t understand exactly how to set it up. My understanding was that the test environment would automatically inherit the packages used by the parent package but when I run test from the Pkg prompt I get an error that the required package is not available in this path. I have written a MWE below,
My package has the following files
Project.toml
name = "MyPkg"
uuid = "a9a052b8-e4c5-4edf-a254-c280e2630dd3"
authors = ["****** ######"]
version = "0.1.0"
[deps]
Random = "9a3f8284-a2c9-5f02-9a11-845980a1fd5c"
src\MyPkg.jl
module MyPkg
using Random
function random()
x = rand(1:5)
return x
end
export random
end # module
test\Project.toml
[deps]
Test = "8dfed614-e22c-5e08-85e1-65c5234f0b40"
test\runtests.jl
using Test
include("../src/MyPkg.jl")
@test MyPkg.random() <= 5
Now when I run,
pkg> activate .
(MyPkg) pkg> test
I get the error,
Testing MyPkg
Status `C:\Users\****\AppData\Local\Temp\jl_T5Nx7K\Project.toml`
[a9a052b8] MyPkg v0.1.0 `C:\Users\******\MyPkg`
[8dfed614] Test
Status `C:\Users\*****\AppData\Local\Temp\jl_T5Nx7K\Manifest.toml`
[a9a052b8] MyPkg v0.1.0 `C:\Users\****\MyPkg`
[2a0f44e3] Base64
[8ba89e20] Distributed
[b77e0a4c] InteractiveUtils
[56ddb016] Logging
[d6f4376e] Markdown
[9a3f8284] Random
[9e88b42a] Serialization
[6462fe0b] Sockets
[8dfed614] Test
ERROR: LoadError: LoadError: ArgumentError: Package Random not found in current path:
- Run `import Pkg; Pkg.add("Random")` to install the Random package.
I don’t want to add the packages again to the test environment because, there is a build step that modifies one of the imported package’s behaviour which would break if it is imported again. Could someone tell me what I am missing here?