Some unit tests modify global variables in the process they run in. Currently, unit tests need to restore those variables when they are completed since the same process may be used to run other unit tests.
I propose to extend testing.T with a new function ExitProcess. When a unit test calls ExitProcess, a new process will be started for subsequent unit tests.
With this change, the following test would succeed:
package main
import "testing"
var globalVariable = 42
func TestMyTest1(t *testing.T) {
if globalVariable!=42 {
t.Fail()
}
globalVariable=43
t.ExitProcess()
}
func TestMyTest2(t *testing.T) {
if globalVariable!=42 {
t.Fail()
}
globalVariable=44
t.ExitProcess()
}
The ExitProcess() function should probably not be supported for parallel tests.