How to pass/use `julia_args` argument to `Pkg.test()`?

I’d like to pass some option(s) to my tests, in particular a flag (or something) that I can pass to include extra (but slow) tests. I can see (12. API Reference · Pkg.jl) that Pkg.test() has keyword arguments julia_args and test_args, but I’m not sure how to use them. I think I can guess how to use test_args, but as I don’t want to test what happens when I pass ARGS to my package, julia_args sounds more like what I want. An example of how to use julia_args in the docs would be really helpful!

I think this is what you want. test_args populates the ARGS global variable, and then you can query that in your test file. Example test/runtests.jl file:

if "run-slow-test" in ARGS
    # do slow stuff

and then use test_args like this:

Pkg.test(; test_args = ["run-slow-test"])

Anyway, here is an example of using julia_args for disabling color and setting number of threads:

Pkg.test(; julia_args = `--color=no --threads=4`)
1 Like

Ah, thanks @fredrikekre - so julia_args is really for passing command line arguments to julia itself (that don’t end up in ARGS). Makes sense in hindsight. I was looking for a way to pass ‘arguments’ to the tests, but I guess that doesn’t really make sense because the tests are really just include()'d, so setting up ARGS is the way to go. I still think a couple of examples would make the docs at 12. API Reference · Pkg.jl clearer.

Agreed, do you want to add it? JuliaLang/Pkg.jl/src/Pkg.jl (line 187).

1 Like