Skip to content

Table tests not recognized when defined inside for-loop #86

@fredrikaverpil

Description

@fredrikaverpil

I just noticed that when you define your table tests like this, neotest-go does not recognize individual tests in the table:

func TestSomething(t *testing.T) {
	t.Parallel()
	t.Run("subtest of table tests", func(t *testing.T) {
		t.Parallel()
		for _, tt := range []struct {
			name string
		}{
			{
				name: "missing",
			},
			{
				name: "invalid",
			},
			{
				name: "wildcard not allowed",
			},
		} {
			tt := tt
			t.Run(tt.name, func(t *testing.T) {
				t.Parallel()
				// Act
				// Assert
			})
		}
	})
}

By rewriting them on the form seen in https://github.com/nvim-neotest/neotest-go/blob/main/neotest_go/many_table_test.go fixes the issue. But when you enter a large pre-existing codebase where table tests are defined this way, this is not a helpful workaround as it's hard to motivate refactoring hundreds of tests for this purpose.

I haven't looked into how neotest-go figures out that there are table tests. Treesitter AST inspection?

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions