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

Multiple tests with a similar name get executed when running go test with -testify.m option #1107

Open
hcbt opened this issue Jul 30, 2021 · 1 comment

Comments

@hcbt
Copy link

hcbt commented Jul 30, 2021

When running my test suite I have noticed that it gets stuck on some tests even if they work fine when I run them independently, each test in suite is independent so order in which you run them does not matter. I have investigated further and noticed that running go test -testify.m TestName runs multiple tests that have a similar name.

For example running:
go test -v mongodb_test.go -testify.m TestMongoDBGetAccount

Gives a following output:

=== RUN   TestGuestAccessTestSuite
=== RUN   TestGuestAccessTestSuite/TestMongoDBGetAccount
time="2021-07-30T14:49:17+03:00" level=info
=== RUN   TestGuestAccessTestSuite/TestMongoDBGetAccountByPortalIDAndUsername
time="2021-07-30T14:49:17+03:00" level=info
=== RUN   TestGuestAccessTestSuite/TestMongoDBGetAccountStatistics
time="2021-07-30T14:49:17+03:00" level=info
=== RUN   TestGuestAccessTestSuite/TestMongoDBGetAccountsByPortal
time="2021-07-30T14:49:17+03:00" level=info
--- PASS: TestGuestAccessTestSuite (0.46s)
    --- PASS: TestGuestAccessTestSuite/TestMongoDBGetAccount (0.05s)
    --- PASS: TestGuestAccessTestSuite/TestMongoDBGetAccountByPortalIDAndUsername (0.10s)
    --- PASS: TestGuestAccessTestSuite/TestMongoDBGetAccountStatistics (0.10s)
    --- PASS: TestGuestAccessTestSuite/TestMongoDBGetAccountsByPortal (0.21s)
PASS
ok  	command-line-arguments	0.475s

Is this an intended behaviour or am I doing something wrong?

@xwjdsh
Copy link

xwjdsh commented Aug 23, 2021

Follow the doc, testify.m means regular expression to select tests of the testify suite to run, the behavior is expected. You need to use go test -v mongodb_test.go -testify.m TestMongoDBGetAccount$ to match.

test % go test -v main_test.go -testify.m=TestMongoDBGetAccount
=== RUN   TestGuestAccessTestSuite
=== RUN   TestGuestAccessTestSuite/TestMongoDBGetAccount
=== RUN   TestGuestAccessTestSuite/TestMongoDBGetAccountByPortalIDAndUsername
--- PASS: TestGuestAccessTestSuite (0.00s)
    --- PASS: TestGuestAccessTestSuite/TestMongoDBGetAccount (0.00s)
    --- PASS: TestGuestAccessTestSuite/TestMongoDBGetAccountByPortalIDAndUsername (0.00s)
PASS
ok      command-line-arguments  0.011s
test % go test -v main_test.go -testify.m=TestMongoDBGetAccount$
=== RUN   TestGuestAccessTestSuite
=== RUN   TestGuestAccessTestSuite/TestMongoDBGetAccount
--- PASS: TestGuestAccessTestSuite (0.00s)
    --- PASS: TestGuestAccessTestSuite/TestMongoDBGetAccount (0.00s)
PASS
ok      command-line-arguments  0.011s
test %

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

2 participants