CallerInfo does not respect t.Helper() calls.
Nobody has claimed this yet.
Assessment
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Newbie friendliness
- 45/100
- Issue type
- Bug
- Clarity
- Mostly clear
- Activity status
- Quiet
- Tech stack
- go
- Domain
- testing-qa
Research direction
Start by reading CallerInfo and the Go testing.T helper behavior, then reproduce the issue with the AssertCount example and assert.Equal. Compare the current trace with the expected output: done means the custom helper frame is omitted while the test caller remains.
Written by the indexing model from the issue text.
Description
Description
I'm trying to implement some custom assertions as part of a test double. I've tried to follow along with the pattern where t.Helper() is called to register my assertion functions as helpers. Within them, I am using testify assertions. Unfortunately, it appears that while the functions all get registered by t.Helper() into t.helperPCs, this information is not used to inform the call trace produced by testify in CallerInfo().
It feels like testify should respect the state in testing.T (although I can see where that might be problematic). Is there another way to get the results desired?
Step To Reproduce
Code like this:
func (s *MyDouble) AssertCount(t assert.TestingT, expected int) {
if h, ok := t.(tHelper); ok {
h.Helper()
}
assert.Equal(t, expected, s.Count(), "unexpected number of items")
}
Expected behavior
I'd like a trace like:
Error Trace: .../somelib_test.go:179
Error: Not equal:
expected: 1
actual : 0
Test: Mytest/thesethingsareequal
Messages: They weren't equal
Actual behavior
Yields a test failure like this:
Error Trace: .../mydouble.go:460
.../somelib_test.go:179
Error: Not equal:
expected: 1
actual : 0
Test: Mytest/thesethingsareequal
Messages: They weren't equal
- Dominant language
- Go
- Stars
- 26.2k
- Forks
- 1.9k
- Avg merge
- 2d 4h
- Merged PRs (30d)
- 2
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
More from stretchr/testify
-
Difficulty 2/5 1-3 hours Newbie friendliness 76/100
-
bug
Difficulty 2/5 1-3 hours Newbie friendliness 88/100
-
bug
Difficulty 1/5 Under an hour Newbie friendliness 88/100
-
enhancement
Difficulty 2/5 1-3 hours Newbie friendliness 72/100
-
internal/cleanup
Difficulty 2/5 1-3 hours Newbie friendliness 68/100
All issues in stretchr/testify
Similar issues
-
optimization optimization:agents-md-curator
Difficulty 2/5 1-3 hours Newbie friendliness 86/100
githubnext/gh-aw-cao#13143 ·
-
Difficulty 2/5 1-3 hours Newbie friendliness 84/100
blinklabs-io/bursa#904 ·
-
Difficulty 2/5 1-3 hours Newbie friendliness 84/100
yanet-platform/ipfw-go#129 ·
-
bug confmap/provider/googlesecretmanagerprovider needs triage
Difficulty 2/5 1-3 hours Newbie friendliness 72/100
open-telemetry/opentelemetry-collector-contrib#51273 · 2 comments ·
-
bug: AI Gateway client filter lists "Unknown" twice when NULL and literal Unknown clients coexist Openbug
Difficulty 2/5 1-3 hours Newbie friendliness 90/100