diff --git a/suite.go b/suite.go index 16bfd15e..b6af9179 100644 --- a/suite.go +++ b/suite.go @@ -522,6 +522,7 @@ func (s *suite) runPickle(pickle *messages.Pickle) (err error) { if s.testingT != nil { // Running scenario as a subtest. s.testingT.Run(pickle.Name, func(t *testing.T) { + ctx = setContextLogger(ctx, t) ctx, err = s.runSteps(ctx, pickle, pickle.Steps) if s.shouldFail(err) { t.Errorf("%+v", err) @@ -536,3 +537,22 @@ func (s *suite) runPickle(pickle *messages.Pickle) (err error) { return err } + +type TestLogger interface { + Log(args ...interface{}) + Logf(format string, args ...interface{}) +} + +type logCtxVal struct{} + +func setContextLogger(ctx context.Context, t TestLogger) context.Context { + return context.WithValue(ctx, logCtxVal{}, t) +} + +func GetTestLogger(ctx context.Context) TestLogger { + t, ok := ctx.Value(logCtxVal{}).(TestLogger) + if !ok { + return nil + } + return t +}