#946 Colorize 'Expected' and 'Actual' in Assert Package + Minor Fixes: #1112, #1086 & #1231#1232
Open
vaguecoder wants to merge 1 commit intostretchr:masterfrom
Open
#946 Colorize 'Expected' and 'Actual' in Assert Package + Minor Fixes: #1112, #1086 & #1231#1232vaguecoder wants to merge 1 commit intostretchr:masterfrom
vaguecoder wants to merge 1 commit intostretchr:masterfrom
Conversation
Contributor
|
This has the problem of inserting color coding into the output even if stdout is not a terminal, or some kind of printer capable of understanding color sequences. Most CI/CD pipelines run outside of a terminal, so this would make the output difficult to read. |
Perhaps a similar approach to package main
import (
"testing"
"github.com/stretchr/testify/require"
)
func init() {
require.SetFlags(require.Fcolorize)
}
func TestMyFunc(t *testing.T) {
require.Equal(t, "Foo", "Bar")
} |
fredbi
added a commit
to fredbi/testify
that referenced
this pull request
Jan 12, 2026
This PR adds support for colorized output, with minimal extra dependencies. - Actual / Expected in equal colorized - Diff output is colorized It is enabled with the specific extra blank import: _ "github.com/go-openapi/testify/enable/colors/v2" When enabled, colorized output is: * enabled by go test flag -testify.colorize * or by environment variable TESTIFY_COLORIZE=true By default, colors are chose to be rendered on a dark terminal. You may use darker colors on a bright terminal with: * go test flag -testify.colorize -testify.theme=light * or by environment variable TESTIFY_THEME=light This work is inspired and adapts the following PRs: * github.com/stretchr#1467 * github.com/stretchr#1480 * github.com/stretchr#1232 * github.com/stretchr#994 Signed-off-by: Frederic BIDON <fredbi@yahoo.com>
5 tasks
fredbi
added a commit
to fredbi/testify
that referenced
this pull request
Jan 12, 2026
This PR adds support for colorized output, with minimal extra dependencies. - Actual / Expected in equal colorized - Diff output is colorized It is enabled with the specific extra blank import: _ "github.com/go-openapi/testify/enable/colors/v2" When enabled, colorized output is: * enabled by go test flag -testify.colorize * or by environment variable TESTIFY_COLORIZE=true By default, colors are chose to be rendered on a dark terminal. You may use darker colors on a bright terminal with: * go test flag -testify.colorize -testify.theme=light * or by environment variable TESTIFY_THEME=light This work is inspired and adapts the following PRs: * github.com/stretchr#1467 * github.com/stretchr#1480 * github.com/stretchr#1232 * github.com/stretchr#994 Signed-off-by: Frederic BIDON <fredbi@yahoo.com>
fredbi
added a commit
to fredbi/testify
that referenced
this pull request
Jan 12, 2026
This PR adds support for colorized output, with minimal extra dependencies. - Actual / Expected in equal colorized - Diff output is colorized It is enabled with the specific extra blank import: _ "github.com/go-openapi/testify/enable/colors/v2" When enabled, colorized output is: * enabled by go test flag -testify.colorized * or by environment variable TESTIFY_COLORIZED=true By default, colors are chose to be rendered on a dark terminal. You may use darker colors on a bright terminal with: * go test flag -testify.colorized -testify.theme=light * or by environment variable TESTIFY_THEME=light This work is inspired and adapts the following PRs: * github.com/stretchr#1467 * github.com/stretchr#1480 * github.com/stretchr#1232 * github.com/stretchr#994 Signed-off-by: Frederic BIDON <fredbi@yahoo.com>
fredbi
added a commit
to fredbi/testify
that referenced
this pull request
Jan 12, 2026
This PR adds support for colorized output, with minimal extra dependencies. - Actual / Expected in equal colorized - Diff output is colorized It is enabled with the specific extra blank import: _ "github.com/go-openapi/testify/enable/colors/v2" When enabled, colorized output is: * enabled by go test flag -testify.colorized * or by environment variable TESTIFY_COLORIZED=true By default, colors are chose to be rendered on a dark terminal. You may use darker colors on a bright terminal with: * go test flag -testify.colorized -testify.theme=light * or by environment variable TESTIFY_THEME=light This work is inspired and adapts the following PRs: * github.com/stretchr#1467 * github.com/stretchr#1480 * github.com/stretchr#1232 * github.com/stretchr#994 Signed-off-by: Frederic BIDON <fredbi@yahoo.com>
fredbi
added a commit
to go-openapi/testify
that referenced
this pull request
Jan 12, 2026
This PR adds support for colorized output, with minimal extra dependencies. - Actual / Expected in equal colorized - Diff output is colorized It is enabled with the specific extra blank import: _ "github.com/go-openapi/testify/enable/colors/v2" When enabled, colorized output is: * enabled by go test flag -testify.colorized * or by environment variable TESTIFY_COLORIZED=true By default, colors are chose to be rendered on a dark terminal. You may use darker colors on a bright terminal with: * go test flag -testify.colorized -testify.theme=light * or by environment variable TESTIFY_THEME=light This work is inspired and adapts the following PRs: * github.com/stretchr#1467 * github.com/stretchr#1480 * github.com/stretchr#1232 * github.com/stretchr#994 Signed-off-by: Frederic BIDON <fredbi@yahoo.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Colorizes
error,expected,actual,testname andmessageof the assert failure cases for better visualization.Changes
InEpsiloncall as per Misplaced "expected" and "actual" Arguments Inside InEpsilonSlice #1231. This was an observation and I opened this issue earlier today.Motivation
Colorizing the output for failure cases makes it easier to visualize. This was first suggested on card #946.
Related Issues
Closes #946
Closes #1231
Additional Notes for Reviewers & Maintainers