Velvet Star Monitor

Standout celebrity highlights with iconic style.

updates

Force retesting or disable test caching

Writer Sophia Terry

Problem:

When I run the same go test twice the second run is not done at all. The results are the cached ones from the first run.

PASS
ok tester/apitests (cached)

Links

I already checked but there is no cli flag for that purpose.

Question:

Is there a possibility to force go test to always run test and not to cache test results.

0

4 Answers

There are a few options as described in the testing flags docs:

  • go clean -testcache: expires all test results
  • use non-cacheable flags on your test run. The idiomatic way is to use -count=1

That said, changes in your code or test code will invalidate the cached test results (there's extended logic when using local files or environment variables as well), so you should not need to invalidate the test cache manually.

7

In Go11, I couldn't disable cache using GOCACHE with modules, I used -count=1 instead:

go test -count=1

Prior to Go11:

GOCACHE=off go test

Or, clean test cache and run test again:

go clean -testcache && go test 

There's also GOCACHE=off mentioned here.

3

The way that I fixed this (I'm using Visual Studio Code on macOS):

Code > Preferences > Settings

Click ... on the right hand side of the settings page

Click Open settings.json

Either:

  1. Add the following snippet to your settings.json file

    "go.testEnvVars": { "GOCACHE": "off"
    }
  2. Change the value of go.testEnvVars to include the following: "GOCACHE": "off"
1

Your Answer

Sign up or log in

Sign up using Google Sign up using Facebook Sign up using Email and Password

Post as a guest

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy