There’s a flag for it
--cache_test_results=(yes|no|auto) (-t)
If this option is set to ‘auto’ (the default) then Bazel will only rerun a test if any of the following conditions applies:
- Bazel detects changes in the test or its dependencies
- the test is marked as
external
- multiple test runs were requested with
--runs_per_test
the test failed.
If ‘no’, all tests will be executed unconditionally.If ‘yes’, the caching behavior will be the same as auto except that it may cache test failures and test runs with
--runs_per_test
.Note that test results are always saved in Bazel’s output tree, regardless of whether this option is enabled, so you needn’t have used
--cache_test_results
on the prior run(s) ofbazel test
in order to get cache hits. The option only affects whether Bazel will use previously saved results, not whether it will save results of the current run.Users who have enabled this option by default in their
.bazelrc
file may find the abbreviations-t
(on) or-t-
(off) convenient for overriding the default on a particular run.
https://docs.bazel.build/versions/master/user-manual.html#flag–cache_test_results