What each runner does with a filter that matches nothing#
Each command below was given a name that no test has.
| Runner | Command | Output | Exit |
|---|---|---|---|
| Go 1.26 | go test -run TestTypo . | ok ex 0.002s [no tests to run] | 0 |
| Vitest 5.1 | vitest run -t zzz | Tests 3 skipped (3) | 0 |
| Node 24 | node --test --test-name-pattern=zzz nt.test.mjs | tests 1, pass 1 | 0 |
| pytest 9.2 | pytest -k zzz | 1 deselected | 5 |
| Playwright 1.65 | playwright test -g zzz | Error: No tests found | 1 |
The Node row is the most misleading. The file holds one test, named real, which did not run. The summary still says one test passed, and the name on that line is the file's. The Node documentation says that tests excluded by the pattern are omitted from the output.
pytest documents exit code 5 as no tests collected. A file filter can behave differently from a name filter in the same runner: vitest run nofile exited 1.
Ways to get there#
- A renamed test, with the old name still in the command.
- Shell quoting.
-t "returns 'x'"passes through two layers of quotes in a script. - A regular expression. A
(,[or+in a test's name changes the match. - The wrong directory or project in a monorepo.
- A flag that accepts emptiness on purpose, such as Playwright's
--pass-with-no-tests, which made the same command exit 0.
Send a count with every filtered result#
go test -count=1 -v -run '^TestExportLimit$' ./apiat4c1e9aa: 1 test, 0 failed, exit 0.
-v prints each test's name, and -count=1 stops Go from answering with a cached result. The equivalent in other runners is a verbose reporter or a JSON report, where the receiver can read the executed names.
The receiver compares two numbers: how many ran, and how many match in the source.
git grep -nE 'func TestExportLimit' 4c1e9aa
Subtests and table tests make the two differ for good reasons, so treat a difference as a question. Zero executed is the one value that always means the result says nothing.
Make it fail in CI#
For a step that must run a named test, assert on the count and not only on the status. In Go:
go test -json -count=1 -run '^TestExportLimit$' ./api > run.json &&
grep -q '"Action":"pass".*"Test":"TestExportLimit"' run.json
The && keeps a failure of go test itself, for example in teardown after the test passed. The second command fails when the test did not pass, including when it did not run. go test writes one JSON event per line, so the pattern only has to match inside a line.
Worked example#
This example is fictional. A handoff says that the regression test passes on the release branch, with the command. Ben reruns it with -v and sees testing: warning: no tests to run. The test was added on main and never picked to the release branch. The evidence was for an absent test, and the decision changes from "ship" to "backport the test and run it".
If the count is right and the exit code is in doubt, look for a pipe that hides it. Return to handing over evidence.