Skip to content

handle t.Parallel in fixtures #56

@IlyasYOY

Description

@IlyasYOY

Thanks for the linter – it’s great.

I wanted to share a use‑case that the current checks don’t cover yet, and suggest a first‑iteration implementation.

Example usage

func TestFoo(t *testing.T) {
    sut := newSUT(t)

    got := sut.Do()

    assert.NotNil(t, got)
}

where the helper looks like:

func newSUT(t *testing.T) *sut {
    t.Helper()
    t.Parallel()

    return &sut{
        // something...
    }
}

In this pattern the test creates a fixture (newSUT) that calls t.Parallel. The linter should be able to detect such cases and ignore them.

Proposed first‑iteration algorithm

  1. Find all calls to unexported functions from a test (*_test.go).
  2. For each such function, check whether it has a *testing.T (or testing.T) parameter.
  3. Scan the function body for a call to t.Parallel().
  4. Recursively analyze any nested helper calls.

This should be relatively straightforward to implement and would catch a large portion of the current false‑positives.

Future extensions

  • Detect similar patterns in functions imported from other packages.
  • Handle additional testing utilities, etc.

Why this matters

Adding this check would directly address the issue discussed in #49, especially since these helper functions are often used in fixtures.

I’d be happy to contribute an implementation if that sounds useful—just let me know the best way to get started!

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions