Skip to content
This repository was archived by the owner on May 9, 2021. It is now read-only.

Skip the "context.Context should be the first parameter of a function" error if the first parameter is *testing.T #248

Closed
wants to merge 1 commit into from

Conversation

AkihiroSuda
Copy link

I'd like to suggest skipping the "context.Context should be the first parameter of a function" error if the first parameter is *testing.T.

The PR allows a code like this:

package foo

import (
  "context"
  "testing"
)

func checkSomething(t *testing.T, ctx context.Context, i int) { .. }

func TestFoo(t *testing.T){
  ctx := ..
  checkSomething(t, ctx, 42)
}

Signed-off-by: Akihiro Suda [email protected]

…" error if the first parameter is *testing.T

Signed-off-by: Akihiro Suda <[email protected]>
@dsnet
Copy link
Member

dsnet commented Oct 15, 2016

Hi. At the moment, golang/go#16221 is targeted to be included in Go 1.8. By adding a Context method to T, it seems to prevent the need for the pattern that you are showing.

@quentinmit
Copy link

I don't think that helps in this case. You likely want to pass a different context to a helper function then the one you get from the T object. For instance, a context that has a timeout.

@AkihiroSuda
Copy link
Author

Ok thank you for comments

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants