Add Test as a dependency of project

So I have a simple and small project that is completely standalone and doesn’t use anything outside of the standard library. The only thing in the standard library that I use is Test for my test suite which is located at test/runtests.jl

I can run the test suite from the root of the project using the command julia --project=. test/runtests.jl and everything runs fine.

However if I run julia --project=. and then press ] to go to Pkg. And then run test I get a failure saying

ERROR: LoadError: ArgumentError: Package Test not found in current path.
- Run `import Pkg; Pkg.add("Test")` to install the Test package.

Both of these are in the same environment so I am confused why this is happening. Also don’t know if this is relevant but I don’t have any packages installed in the global Julia environment. That is if I don’t specify a project, then go to Pkg, and type status it is empty.

If I add Test both ways of running the test suite work. But I would like to understand the discrepancy for future reference.

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

test = ["Test"]

@jling I’m sorry could you elaborate more on how this explains the discrepancy I am seeing

When you run a test via Pkg, the tests are not run in the current project but instead a new project which additionally includes dependencies in the extras.test list in Project.toml.

So in most packages you put Test into this list but don’t include it in the main deps because the package itself doesn’t normally require it.

@cjdoris why does it work when I don’t add Test and run it via the command line directly? I didn’t have Test in my project either when I ran that. That goes for all standard library packages. I can use them without adding them in Pkg.

When you run anything at the top level (eg a script or the REPL) you can use any package in the load path, which normally includes the current project, the global v1.8 project and all the stdlibs.

However when a package is imported it can only use whatever is listed in its Project.toml deps and when a package is tested it can use only it’s Project.toml deps and extras.test.

1 Like

When you run anything at the top level (eg a script or the REPL)

What other ways are there to run Julia? I.e how doest the test command run Julia in a way that only uses what is explicitly stated in our Project.toml file