Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Test panics when parallel suites contain parameterized tests #104

Open
andrey-kuznetsov opened this issue Dec 26, 2024 · 0 comments
Open

Comments

@andrey-kuznetsov
Copy link

Describe the bug
I use parameterized tests inside parallel suites. This construct panics by default. The fix is simple yet not obvious: child suite should implement ParametrizedSuite interface.

To Reproduce
parent_test.go:

package nestedtabletest

import (
	"testing"

	"github.com/ozontech/allure-go/pkg/framework/provider"
	"github.com/ozontech/allure-go/pkg/framework/suite"
)

type ParentSuite struct {
	suite.Suite
}

type testCaseParams struct {
	Name string
	Age  int
}

var params []testCaseParams = []testCaseParams{
	{Name: "Alice", Age: 19},
	{Name: "Bob", Age: 23},
}

func (s *ParentSuite) TestFirstChildSuite(t provider.T) {
	t.Parallel()
	s.RunSuite(t, &FirstChildSuite{ParamAgeValidity: params})
}

func (s *ParentSuite) TestSecondChildSuite(t provider.T) {
	t.Parallel()
	s.RunSuite(t, &SecondChildSuite{ParamPersonNameEmptiness: params})
}

func TestSomething(t *testing.T) {
	suite.RunSuite(t, new(ParentSuite))
}

child1_test.go:

package nestedtabletest

import (
	"github.com/ozontech/allure-go/pkg/framework/provider"
	"github.com/ozontech/allure-go/pkg/framework/suite"
)

type FirstChildSuite struct {
	suite.Suite
	ParamAgeValidity []testCaseParams
}

// Uncomment to fix
// func (s *FirstChildSuite) InitializeTestsParams() {}

func (s *FirstChildSuite) TableTestAgeValidity(t provider.T, p testCaseParams) {
	t.Assert().GreaterOrEqual(p.Age, 18)
}

child2_test.go

package nestedtabletest

import (
	"github.com/ozontech/allure-go/pkg/framework/provider"
	"github.com/ozontech/allure-go/pkg/framework/suite"
)

type SecondChildSuite struct {
	suite.Suite
	ParamPersonNameEmptiness []testCaseParams
}

// Uncomment to fix
// func (s *SecondChildSuite) InitializeTestsParams() {}

func (s *SecondChildSuite) TableTestPersonNameEmptiness(t provider.T, p testCaseParams) {
	t.Assert().NotEmpty(p.Name)
}

This fails with

$ go test
--- FAIL: TestSomething (0.00s)
    --- FAIL: TestSomething/ParentSuite (0.00s)
        --- FAIL: TestSomething/ParentSuite/Tests (0.00s)
            --- FAIL: TestSomething/ParentSuite/Tests/TestFirstChildSuite (0.00s)
                --- FAIL: TestSomething/ParentSuite/Tests/TestFirstChildSuite/FirstChildSuite (0.00s)
                    --- FAIL: TestSomething/ParentSuite/Tests/TestFirstChildSuite/FirstChildSuite/Tests (0.00s)
                        --- FAIL: TestSomething/ParentSuite/Tests/TestFirstChildSuite/FirstChildSuite/Tests/TableTestAgeValidity (0.00s)
                            errors_handling.go:28: test panicked: reflect: Call with too few input arguments
                                goroutine 27 [running]:
                                runtime/debug.Stack()
                                	/snap/go/10748/src/runtime/debug/stack.go:26 +0x5e
                                github.com/ozontech/allure-go/pkg/framework/runner.(*runner).RunTests.func1.3.1.3()
                                	/home/andkuznetsoff/go/pkg/mod/github.com/ozontech/allure-go/pkg/[email protected]/runner/runner.go:188 +0x74
                                panic({0x70a980?, 0x7fdd70?})
                                	/snap/go/10748/src/runtime/panic.go:785 +0x132
                                reflect.Value.call({0xc000156b40?, 0xc0001243a8?, 0x775780?}, {0x776295, 0x4}, {0xc0001d2030, 0x2, 0x2?})
                                	/snap/go/10748/src/reflect/value.go:424 +0x1bef
                                reflect.Value.Call({0xc000156b40?, 0xc0001243a8?, 0x6e189c?}, {0xc0001d2030?, 0x775780?, 0xc00011f290?})
                                	/snap/go/10748/src/reflect/value.go:365 +0xb9
                                github.com/ozontech/allure-go/pkg/framework/runner.(*testMethod).GetBody.func1({0x808be0?, 0xc000132960?})
                                	/home/andkuznetsoff/go/pkg/mod/github.com/ozontech/allure-go/pkg/[email protected]/runner/tests.go:155 +0x25a
                                github.com/ozontech/allure-go/pkg/framework/runner.(*runner).RunTests.func1.3.1(0xc00014d520)
                                	/home/andkuznetsoff/go/pkg/mod/github.com/ozontech/allure-go/pkg/[email protected]/runner/runner.go:206 +0x379
                                testing.tRunner(0xc00014d520, 0xc000156cd0)
                                	/snap/go/10748/src/testing/testing.go:1690 +0xf4
                                created by testing.(*T).Run in goroutine 26
                                	/snap/go/10748/src/testing/testing.go:1743 +0x390
            --- FAIL: TestSomething/ParentSuite/Tests/TestSecondChildSuite (0.00s)
                --- FAIL: TestSomething/ParentSuite/Tests/TestSecondChildSuite/SecondChildSuite (0.00s)
                    --- FAIL: TestSomething/ParentSuite/Tests/TestSecondChildSuite/SecondChildSuite/Tests (0.00s)
                        --- FAIL: TestSomething/ParentSuite/Tests/TestSecondChildSuite/SecondChildSuite/Tests/TableTestPersonNameEmptiness (0.00s)
                            errors_handling.go:28: test panicked: reflect: Call with too few input arguments
                                goroutine 7 [running]:
                                runtime/debug.Stack()
                                	/snap/go/10748/src/runtime/debug/stack.go:26 +0x5e
                                github.com/ozontech/allure-go/pkg/framework/runner.(*runner).RunTests.func1.3.1.3()
                                	/home/andkuznetsoff/go/pkg/mod/github.com/ozontech/allure-go/pkg/[email protected]/runner/runner.go:188 +0x74
                                panic({0x70a980?, 0x7fdd70?})
                                	/snap/go/10748/src/runtime/panic.go:785 +0x132
                                reflect.Value.call({0xc00021e1e0?, 0xc0002040c8?, 0x775780?}, {0x776295, 0x4}, {0xc0000160c0, 0x2, 0x2?})
                                	/snap/go/10748/src/reflect/value.go:424 +0x1bef
                                reflect.Value.Call({0xc00021e1e0?, 0xc0002040c8?, 0x6e189c?}, {0xc0000160c0?, 0x775780?, 0xc0000301a0?})
                                	/snap/go/10748/src/reflect/value.go:365 +0xb9
                                github.com/ozontech/allure-go/pkg/framework/runner.(*testMethod).GetBody.func1({0x808be0?, 0xc00003c2a0?})
                                	/home/andkuznetsoff/go/pkg/mod/github.com/ozontech/allure-go/pkg/[email protected]/runner/tests.go:155 +0x25a
                                github.com/ozontech/allure-go/pkg/framework/runner.(*runner).RunTests.func1.3.1(0xc0000a24e0)
                                	/home/andkuznetsoff/go/pkg/mod/github.com/ozontech/allure-go/pkg/[email protected]/runner/runner.go:206 +0x379
                                testing.tRunner(0xc0000a24e0, 0xc00009e050)
                                	/snap/go/10748/src/testing/testing.go:1690 +0xf4
                                created by testing.(*T).Run in goroutine 6
                                	/snap/go/10748/src/testing/testing.go:1743 +0x390
FAIL
exit status 1
FAIL	nestedtabletest	0.004s

Expected behavior
Tests pass.

Additional context
Add any other context about the problem here.

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

No branches or pull requests

1 participant