Skip to content

fix the output source file in test output#1026

Merged
boyan-soubachov merged 2 commits intostretchr:masterfrom
fefe982:compare_helper
Jan 15, 2021
Merged

fix the output source file in test output#1026
boyan-soubachov merged 2 commits intostretchr:masterfrom
fefe982:compare_helper

Conversation

@fefe982
Copy link

@fefe982 fefe982 commented Nov 20, 2020

Summary

The file name in the failed summary shows files inside the testify package, instead the real testing file. E.ge

--- FAIL: TestCurrentCache (0.12s)
    assertion_compare.go:221: 
                Error Trace:    xxxx_test.go:352
                Error:          Elements should be the same type
                Test:           TestXXXX
                Messages:       []

The assertion_compare.go is a file inside testify package. It should also show xxxx_test.go:352 as the Error Trace.

Changes

Make functions inside testify package as test helpers with:

	if h, ok := t.(tHelper); ok {
		h.Helper()
	}

Motivation

With this PR, the filename and number would correctly show xxxx_test.go:352

Related issues

Copy link
Collaborator

@boyan-soubachov boyan-soubachov left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for this. Unfortunately this will slow down test execution speed but it has caught a reversion.

Could you possibly add a unit test to cover this problem and prevent the reversion from happening again in the future?

@fefe982
Copy link
Author

fefe982 commented Jan 15, 2021

Add some test. The implementation of the Helper function in the test is directly copied for the test package. The test ensures that the Helper function is called.

Copy link
Collaborator

@boyan-soubachov boyan-soubachov left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks great. Thank you!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants