stretchr/testify · error
Copy() is deprecated
Error message
Copy() is deprecated
What it means
CollectT.Copy() (assert/assertions.go:2070) is an unconditionally panicking stub marked Deprecated. Like Reset, it was an internal method that leaked into the public API and was removed; calling it always panics. It was intended to copy collected errors onto another TestingT.
Source
Thrown at assert/assertions.go:2071
// Errorf collects the error.
func (c *CollectT) Errorf(format string, args ...interface{}) {
c.errors = append(c.errors, fmt.Errorf(format, args...))
}
// FailNow stops execution by calling runtime.Goexit.
func (c *CollectT) FailNow() {
c.fail()
runtime.Goexit()
}
// Deprecated: That was a method for internal usage that should not have been published. Now just panics.
func (*CollectT) Reset() {
panic("Reset() is deprecated")
}
// Deprecated: That was a method for internal usage that should not have been published. Now just panics.
func (*CollectT) Copy(TestingT) {
panic("Copy() is deprecated")
}
func (c *CollectT) fail() {
if !c.failed() {
c.errors = []error{} // Make it non-nil to mark a failure.
}
}
func (c *CollectT) failed() bool {
return c.errors != nil
}
// EventuallyWithT asserts that given condition will be met in waitFor time,
// periodically checking target function each tick. In contrast to Eventually,
// it supplies a CollectT to the condition function, so that the condition
// function can use the CollectT to call other assertions.
// The condition is considered "met" if no errors are raised in a tick.
// The supplied CollectT collects all errors from one tick (if there are any).View on GitHub (pinned to 001eb7946b)
Solutions
- Replace Copy(t) with manual error propagation: iterate collectT.Errors() and call t.Errorf for each.
- Use assert.Fail or the modern CollectT integration with EventuallyWithT which handles propagation automatically.
- Delete the Copy call if the errors are no longer needed on the target.
Example fix
// before
collectT.Copy(t)
// after
for _, e := range collectT.Errors() {
t.Errorf("%v", e)
} Defensive patterns
Strategy: validation
Validate before calling
// Static prevention: replace collectT.Copy(t) with manual propagation.
func propagateErrors(c *assert.CollectT, t *testing.T) {
for _, e := range c.Errors() {
t.Errorf("%v", e)
}
} Try / catch
// Copy() always panics; recover is pointless. // Use the manual propagation helper above in place of Copy.
Prevention
- After upgrading testify, grep for '.Copy(' on CollectT and replace.
- Track the changelog entry that removed Copy.
- Centralize CollectT error propagation in one helper.
When it happens
Trigger: Calling collectT.Copy(otherT) on a *assert.CollectT — typically legacy code that manually propagated collected errors to a real *testing.T.
Common situations: Code written against an old testify version where Copy was functional; copy-pasted patterns from deprecated docs; upgrading testify and hitting the panic at runtime.
Related errors
- Reset() is deprecated
- test failed and t is missing `FailNow()`
- cannot use Func in expectations. Use mock.AnythingOfType("%T
- not before calls must be created with Mock.On()
- assert: arguments: %s is not a func
AI-assisted analysis of stretchr/testify@001eb7946b (2026-08-04).
Data as JSON: /data/errors/b7f549f0bbd11db2.json.
Report an issue: GitHub.