如何将TestMain与全局aetest.NewInstance一起使用

I am using "google.golang.org/appengine/aetest" package and setup my TestMain like this:

var myAeInst aetest.Instance


func TestMain(m *testing.M) {
    var err error
    myAeInst, err = aetest.NewInstance(&aetest.Options{StronglyConsistentDatastore: true})
    defer tearDown()

    c := m.Run()

    os.Exit(code)
}

func tearDown() {
    if myAeInst != nil {
        myAeInst.Close()
    }
}

But it stuck at aetest.NewInstance, any one encounter similar issue?

You're calling defer tearDown() and then os.Exit(code), which calls tearDown after os.Exit (i.e., never). You need to either explicitly call tearDown before os.Exit, or make a new function that you defer from that doesn't call os.Exit.