I’m developing a package and I have a test folder with a runtest.jl file and other test files.
The runtest.jl is the following
using Test, TestSetExtensions
@testset ExtendedTestSet "Wasabi tests" begin
If I run test from Pkg in the julia repl everything works fine.
Some tests take lot of time to run, so I want to be able to run only a specific testset and ignore others.
Running the runtest.jl directly I can do
julia test/runtest.jl nameoftest
But that doesn’t work since I get
LoadError: ArgumentError: Package TestSetExtensions not found in current path.
Following the doc I don’t have any test specific dependency in the project but I have a project.toml file under test/
I’ve also tried
julia --project=./test test/runtests.jl builder
but I got
LoadError: ArgumentError: Package Wasabi not found in current path
where Wasabi is the package I’m currently working on.
Take a look at ReTest.jl. It is semi-compatible with the native test structure (via hijack), and it offers selective test running as a service. I find it useful occasionallly, even though it fails to cope sometimes.
# Hook into Pkg.test so that tests from a single file can be run. For example,
# to run only the MVector and SVector tests, use:
# Pkg.test("StaticArrays", test_args=["MVector", "SVector"])
enabled_tests = lowercase.(ARGS)
key = lowercase(splitext(fname))
if isempty(enabled_tests) || key in enabled_tests
Then, write your tests in separate files and add calls in runtests.jl like addtests("test_file1.jl").
I expect to move to TestItems and TestItemRunner soon, though.
This is a cool idea! I enhanced it slightly, now my runtests.jl file looks like this:
smartcase = any(isuppercase, join(ARGS)) ? identity : lowercase
filter(readdir()) do file
return endswith(file, ".jl") &&
!startswith(file, ['.', '#']) &&
file != "runtests.jl" &&
(isempty(ARGS) || any(occursin(smartcase(file)), ARGS))
end .|> include
It basically auto-discovers test files in the test directory, but runs only those which contain any of the CLI arguments as substrings. The script uses smartcase matching, i.e., if the CLI arguments contain uppercase letters, then substring matching is case-sensitive, otherwise it is case-insensitive.
And then tests are invoked with the following command:
$ alias jlt='julia --project -e "using Pkg; Pkg.test(test_args = ARGS)"'
$ jlt sub str