Special environment for testing?

In order to test a package, I would like to use a test environment which would include many other packages, on which the tested package does not depend. I think it should be possible to have an ad hoc environment in the test folder (is that a thing?), but so far I have not been able to make it work.

Any ideas?

Yes, that is the w
ay it is supposed to work… for example in the test environment I have CSV to load some small dataset, but then the tested package doem*t depwnds on it…

Thanks for the confirmation. I think I am now on the right track: I made a project in the test folder, and added the packages that I require to that environment. It looks like it might work.

  1. Make an environment in the folder TestedPackage/test.
  2. Add all the packages that are necessary to run the test to that environment.
  3. In the folder TestedPackage one can now run ]test.

You can ]test in the root directory of the package, it automatically uses the test environment.

Update: see the Pkg documentation on this.

BTW when developing a package pkgname I got used to start Julia with julia --project=@pkgname which creates an environment in the .julia/environments folder (I think since 1.7). This avoids accidental addition of dependecies to the package (which itself needs to be dev-d to that environment).
And you can do ]test pkgname.

1 Like

All: that is a solution, but beware, there’s a catch. The Manifest.toml in the test folder
could interfere with the manifest of the package. I now remove the Manifest.toml in the test folder
before the tests run. The issue was reported a while ago: "cannot merge projects" error · Issue #1585 · JuliaLang/Pkg.jl · GitHub

@PetrKryslUCSD , not to add to give information overload, but I wrote up a tutorial for this for the Julia docs for the upcoming 1.9 release: Unit Testing · The Julia Language I wrote it for my student assistants who were having trouble writing tests – let me know if it could use some improvements!

1 Like

I usually test with the standards tests and TestEnv.jl

Citing this:

1 Like

Does it address the Manifest problem?

It creates a temporary manifest each time.

1 Like

I have to take it back: I do not have a solution at the moment.

The compatibility entry of the Project.toml of the test folder is ignored. I get Arpack 0.5.4
even though my test Project.toml clearly states

Arpack = "0.5.3"

Arpack 0.5.4 is shot in some as yet obscure way (eigs() doesn't work in my computer, but works in another one. · Issue #147 · JuliaLinearAlgebra/Arpack.jl · GitHub), which is why I wanted 0.5.3. But: how do I get it if the compatibility section doesn’t work?

Edit: I forgot “= 0.5.3”! Silly me. So the solution described above works.

1 Like