You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Describe the bug
When running tests in parallel with the JSON flag, for example, using go test -v -json ./..., the logs become mixed up between tests. For instance, logs intended for one test appear in the output of another, making it difficult to distinguish which logs belong to which test.
To Reproduce
Run the following tests, with the following command go test -json -v ./...
...
{"Time":"2024-10-25T18:09:16.435283509+01:00","Action":"output","Package":"go_playground/pkg/something","Test":"Test2","Output":"Test1 2024-10-25T18:09:16+01:00 something_test.go:10: This
is a log
"}
{"Time":"2024-10-25T18:09:16.435295209+01:00","Action":"output","Package":"go_playground/pkg/something","Test":"Test1","Output":"--- PASS: Test1 (0.00s)
"}
{"Time":"2024-10-25T18:09:16.435312409+01:00","Action":"output","Package":"go_playground/pkg/something","Test":"Test1","Output":"Test2 2024-10-25T18:09:16+01:00 something_test.go:10: This
is a log
"}
{"Time":"2024-10-25T18:09:16.435322709+01:00","Action":"output","Package":"go_playground/pkg/something","Test":"Test1","Output":"Test2 2024-10-25T18:09:16+01:00 something_test.go:10: This
is a log
"}
{"Time":"2024-10-25T18:09:16.435332709+01:00","Action":"output","Package":"go_playground/pkg/something","Test":"Test1","Output":"Test2 2024-10-25T18:09:16+01:00 something_test.go:10: This
is a log
"}
{"Time":"2024-10-25T18:09:16.435349509+01:00","Action":"output","Package":"go_playground/pkg/something","Test":"Test1","Output":"Test2 2024-10-25T18:09:16+01:00 something_test.go:10: This
is a log
"}
{"Time":"2024-10-25T18:09:16.43541831+01:00","Action":"output","Package":"go_playground/pkg/something","Test":"Test1","Output":"Test2 2024-10-25T18:09:16+01:00 something_test.go:10: This i
s a log
"}
...
Where Test does not match the test name at the start of the line
Expected behavior
I am expecting the log that contains the test name to match the log in the json.
Nice to have
Terminal output
Screenshots
Versions
Terratest version: v0.47.2
Environment details:
Additional context
After doing some digging I believe the issue comes from the logger package.
The DoLog method seems to use fmt.Fprintln instead of the t.Log provided by golang that is intended to be used during testing.
In the reproduce tests if I change the log function to use the t.Log() it works without issues.
funclog(t*testing.T) {
t.Log(t.Name(), "This is a log")
}
The text was updated successfully, but these errors were encountered:
Describe the bug
When running tests in parallel with the JSON flag, for example, using go test -v -json ./..., the logs become mixed up between tests. For instance, logs intended for one test appear in the output of another, making it difficult to distinguish which logs belong to which test.
To Reproduce
Run the following tests, with the following command
go test -json -v ./...
Which will result in this:
Where
Test
does not match the test name at the start of the lineExpected behavior
I am expecting the log that contains the test name to match the log in the json.
Nice to have
Versions
Additional context
After doing some digging I believe the issue comes from the logger package.
The
DoLog
method seems to usefmt.Fprintln
instead of thet.Log
provided by golang that is intended to be used during testing.In the reproduce tests if I change the log function to use the
t.Log()
it works without issues.The text was updated successfully, but these errors were encountered: