Do you have a custom test_runner?
See for the default implementation in your zig subfolder: lib/compiler/test_runner.zig.
When using zig test, you can specify the test_runner with the option:
--test-runner [path] Specify a custom test runner
Using build.zig, you can specify test_runner in addTest TestOptions
const tests = b.addTest(.{
.target = target,
.root_source_file = root_source_file,
.test_runner = b.path("test_runner.zig"),
});