If require object hasn't been initialized before calling suite.Require method, it will be created on the base of *testing.T returned from suite.T() (code):
// Require returns a require context for suite.
func (suite *Suite) Require() *require.Assertions {
suite.mu.Lock()
defer suite.mu.Unlock()
if suite.require == nil {
suite.require = require.New(suite.T())
}
return suite.require
}
This will result in a deadlock because suite.T() wants to acquire the lock that has been already acquired:
// T retrieves the current *testing.T context.
func (suite *Suite) T() *testing.T {
suite.mu.RLock()
defer suite.mu.RUnlock()
return suite.t
}
If
require
object hasn't been initialized before callingsuite.Require
method, it will be created on the base of*testing.T
returned fromsuite.T()
(code):This will result in a deadlock because
suite.T()
wants to acquire the lock that has been already acquired: