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

@testset for: avoid calling finish twice when it errors #41715

Merged
merged 2 commits into from
May 17, 2022

Conversation

rfourquet
Copy link
Member

Here is a MWE:

julia> using Test
       @testset "a" for i=1:2
           @test i != 1
       end
a: Test Failed at REPL[3]:3
  Expression: i != 1
   Evaluated: 1 != 1
Stacktrace:
[...]
Test Summary: | Fail  Total
a             |    1      1
Test Summary: | Fail  Total
a             |    1      1
ERROR: Some tests did not pass: 0 passed, 1 failed, 0 errored, 0 broken.

caused by: Some tests did not pass: 0 passed, 1 failed, 0 errored, 0 broken.

The finish function is called twice, and for a toplevel testset, this means
throwing an error. This manifests in the above example by printing twice
the result of the testset (with "Test Summary"), and by having
"Error: ... caused by: ..." with the same message.

I'm not sure whether this is a correct fix (and the two level of try blocks, together with the "first_iteration" trick are a bit complex for me), and I don't know how to write a test for it. But otherwise this can at least serve as a bug report.

cc. @yuyichao who introduced some related changes in #18011.

Here is a MWE:
```julia
julia> using Test
       @testset "a" for i=1:2
           @test i != 1
       end
a: Test Failed at REPL[3]:3
  Expression: i != 1
   Evaluated: 1 != 1
Stacktrace:
[...]
Test Summary: | Fail  Total
a             |    1      1
Test Summary: | Fail  Total
a             |    1      1
ERROR: Some tests did not pass: 0 passed, 1 failed, 0 errored, 0 broken.

caused by: Some tests did not pass: 0 passed, 1 failed, 0 errored, 0 broken.
```

The `finish` function is called twice, and for a toplevel testset, this means
throwing an error. This manifests in the above example by printing twice
the result of the testset (with "Test Summary"), and by having
"Error: ... caused by: ..." with the same message.
@rfourquet rfourquet added kind:bugfix This change fixes an existing bug testsystem The unit testing framework and Test stdlib labels Jul 27, 2021
@@ -1345,7 +1345,10 @@ function testset_forloop(args, testloop, source)
# they can be handled properly by `finally` lowering.
if !first_iteration
pop_testset()
finish_errored = true
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe

Suggested change
finish_errored = true
finish_threw = true

is more precise?

@KristofferC KristofferC added the status:merge me PR is reviewed. Merge when all tests are passing label May 17, 2022
@KristofferC KristofferC merged commit 4605704 into master May 17, 2022
@KristofferC KristofferC deleted the rf/testset-for-double-fail branch May 17, 2022 16:35
@giordano giordano removed the status:merge me PR is reviewed. Merge when all tests are passing label Jun 10, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
kind:bugfix This change fixes an existing bug testsystem The unit testing framework and Test stdlib
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants