You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
import"testing"import"github.com/ory/dockertest"funcTestMain(m*testing.M) {
pool, _:=dockertest.NewPool("")
resource, _:=pool.Run("mysql", "5.7", []string{"MYSQL_ROOT_PASSWORD=secret"}) // Create and run containerdeferpool.Purge(resource) // Kill containerm.Run()
}
funcTestXXX(t*testing.T) {
// Do some tests using mysql container running
}
y_test.go
import"testing"import"github.com/ory/dockertest"funcTestMain(m*testing.M) {
pool, _:=dockertest.NewPool("")
resource, _:=pool.Run("mysql", "5.7", []string{"MYSQL_ROOT_PASSWORD=secret"}) // Create and run containerdeferpool.Purge(resource) // Kill containerm.Run()
}
funcTestYYY(t*testing.T) {
// Do some tests using mysql container running
}
If I run the tests in each directory separately, it works perfectly:
It creates mysql container.
It Runs the tests.
It kills the docker container
Tests end and test results returned
If however I run go test -v ./... from the parent directory:
The tests error out at pool.Run saying that mysql container already exists.
I believe the correct behaviour should be that TestMain should be run independently and sequentially. Only After outer TestMain returns should the inner packages be tested.
That way the containers are already killed before the inner packages are tested, giving the opportunity for the inner package to create their own container (and cleanup themself)
The text was updated successfully, but these errors were encountered:
pjebs
changed the title
testing: TestMain not working properly
testing: TestMain not working sequentially
Jul 28, 2022
Package Structure:
x_test.go
y_test.go
If I run the tests in each directory separately, it works perfectly:
If however I run
go test -v ./...
from the parent directory:The tests error out at
pool.Run
saying that mysql container already exists.I believe the correct behaviour should be that TestMain should be run independently and sequentially. Only After outer TestMain returns should the inner packages be tested.
That way the containers are already killed before the inner packages are tested, giving the opportunity for the inner package to create their own container (and cleanup themself)
The text was updated successfully, but these errors were encountered: