stretchr / testify

A toolkit with common assertions and mocks that plays nicely with the standard library
MIT License
22.51k stars 1.56k forks source link

Suite Panics have incorrect trace #771

Open Naatan opened 5 years ago

Naatan commented 5 years ago

When a panic occurs I'm seeing the following error:

suite.go:61: test panicked: runtime error: invalid memory address or nil pointer dereference

suite.go does not exist anywhere in my project, I'm not sure where it's coming from. If I have multiple panics they all show this file and line number.

My test suite struct itself inherits from an intermediary test suite which in turn inherits from the testify test suite, I suspect this might be related.

I think the problem here is that testify uses hard coded skip values for generating its trace.

I think there are 2 things that could (should) be done to address this:

marcel commented 5 years ago

I am not doing any unusual embedding with intermediary test suites. This is a regression.

go version go1.12.6 darwin/amd64

A quick (noisy) work-around:

--- a/vendor/github.com/stretchr/testify/suite/suite.go
+++ b/vendor/github.com/stretchr/testify/suite/suite.go
@@ -6,6 +6,7 @@ import (
        "os"
        "reflect"
        "regexp"
+       "runtime/debug"
        "testing"

        "github.com/stretchr/testify/assert"
@@ -59,6 +60,7 @@ func failOnPanic(t *testing.T) {
        r := recover()
        if r != nil {
                t.Errorf("test panicked: %v", r)
+               debug.PrintStack()
                t.FailNow()
        }
 }
marcel commented 5 years ago

Looks like this was fixed months ago. It just hasn't been released yet. Though it's in master: https://github.com/stretchr/testify/commit/10a9f474263e7c93475ac7aa9f2661449fc45cb3

kubaj commented 4 years ago

I've tested latest release v1.4.0 and it's fixed for me