mardi 9 janvier 2018

golang test setup for entire test run/package

Is there a way to specify code to be run before all the tests in the current test run? Even when running tests across deeply nested directories? e.g.

a/
a/a_test.go
b/c/
b/c/c_test.go
d_test.go

I want to write some code that runs once before and once after all the tests in files a_test.go, c_test.go, d_test.go have run.

I know about TestMain, which sorta does what I want if I needed to do this at the package level, but this doesn't run before/after all the tests in subdirectories/subpackages. I want something that's one level above TestMain.

I'm looking for something akin to nosetests's SetUpPackage or pytest's session scoped fixtures.

Aucun commentaire:

Enregistrer un commentaire