Skip to content

testing: handle panics in subtests in order to print errors and log info #25021

@stephens2424

Description

@stephens2424

What version of Go are you using (go version)?

1.10.1

Does this issue reproduce with the latest release?

Yes

What operating system and processor architecture are you using (go env)?

OS X, Windows, App Engine (playground)

What did you do?

https://play.golang.org/p/4-VN_VdQnrc

What did you expect to see?

I expected to see the error that occurred to be printed, and then the panic.

What did you see instead?

I see only the panic.

The exact use case I have is a table test where each subtest is using a different version of an external resource (message queue). An early subtest fails to perform some setup and leaves an internal thing in a bad state, so I expect my tests to not work fully at this point. However, because the later subtest panics when it encounters that bad state, the whole test function aborts without my previous calls to t.Error or t.Fatal (in the previous subtest) having their contents printed. Because of this, I lost critical error information that would have pointed me to the real issue with the earlier subtest's setup. Since the earlier subtest didn't print anything, its problem was not apparent.

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions