Hello,
I created my own package (let’s call it MyPackage) with Pkg (generate
, add
, etc.), locally (not registered), and I have some problems to test it.
I used the latest method described here: I have a test folder inside my package root, which contains runtests.jl, Manifest.toml and Project.toml. It imports Test package (installed by ] activate test
then add Test
and other packages useful for tests).
Inside runtests.jl, it starts with
using Test
using MyPackage
When I am in MyPackage root folder and I run ] test
, I have this error:
(MyPackage) pkg> test
Testing MyPackage
Status `/tmp/jl_PPbTYN/Manifest.toml`
[…]
ERROR: LoadError: ArgumentError: Package MyPackage not found in current path:
- Run `import Pkg; Pkg.add("MyPackage")` to install the MyPackage package.
Stacktrace:
[1] require(::Module, ::Symbol) at ./loading.jl:892
[2] include(::String) at ./client.jl:439
[3] top-level scope at none:6
in expression starting at […]/MyPackage/test/runtests.jl:11
ERROR: Package MyPackage errored during testing
Of course, my package is not registered so I can’t simply do Pkg.add("MyPackage")
:
ERROR: LoadError: expected package `MyPackage […]` to be registered
And Pkg.add(".")
does not work inside runtests.jl file:
ERROR: LoadError: `.` is not a valid package name
If I do ] activate test
then add .
, it adds MyPackage and all its dependencies, so both the Manifest.toml are pretty similar, just MyPackage/test’s has MyPackage (with repo-rev = "master"
and repo-url = ".."
lines in addition) and Test packages in addition, and in Project.toml, "MyPackage" = "…"
line is added (with quotes, compared to other packages). In this setting, if I test again by ] test
from MyPackage root folder, I have this error:
(MyPackage) pkg> test
Testing MyPackage
ERROR: can not merge projects
It is not a version mismatch problem because I updated both MyPackage and MyPackage/test environments’ dependencies (everything is identical, except the addition of Test package in test).
My only working attempt is just to add this line inside runtests.jl (without adding MyPackage explicitely by add .
, as tried in the previous step):
using Test
Pkg.activate("..") # This line!
cd("..") # For configuration files (is there a prettier way?), not so important for this example.
using MyPackage
So it means that by running test, it moves to test environment, activates it, imports Test, then activates the parent environment it is testing… It seems pretty odd to do that manually, especially when the Pkg documentation says for this part:
Note that Pkg will add the tested package itself implictly.
So I think I missed something…
So, my general question is: with a unregistered custom package, what is the latest and best way to test it, rather than just using Pkg.activate("..")
?
Second extra question (related to a comment in the last script I have shown): is there a prettier way to manage the change of working folder for tests in regard to configuration and data files, rather than using cd("..")
?
Sincerely.