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

Tests don't fail when exception is thrown #177

Closed
kenahoo opened this issue Sep 3, 2024 · 5 comments · Fixed by #178
Closed

Tests don't fail when exception is thrown #177

kenahoo opened this issue Sep 3, 2024 · 5 comments · Fixed by #178

Comments

@kenahoo
Copy link

kenahoo commented Sep 3, 2024

It appears that if a @testitem in runtests.jl throws an exception, the overall test process still returns status 0, i.e., success.

Here's a minimal working example:

% cat test/runtests.jl 
using Test
using ReTestItems

@testitem "Example tests" begin
    error("Fail")
end


% julia --project=. -e 'using Pkg; Pkg.test()'
...
     Testing Running tests...
12:31:04 | maxrss  0.9% | mem 100.0% | START test item "Example tests" at runtests.jl:4
Example tests: Error During Test at /Users/.../Inflect.jl/test/runtests.jl:4
  Got exception outside of a @test
...
Test Summary: | Error  Total  Time
Example tests |     1      1  1.5s
12:31:06 | maxrss  1.2% | mem 99.9% | DONE test item "Example tests" 0 secs
     Testing Inflect tests passed 


% echo $?                                     
0

Notice the Testing Inflect tests passed message and the exit status.

Thoughts on why this is happening and how to fix it?

@nickrobinson251
Copy link
Collaborator

nickrobinson251 commented Sep 3, 2024

thanks for using the package!

@testitem cannot be places in runtests.jl, only in a file named with the suffix *_test.jl or *_tests.jl -- note runtests.jl does not meet this convention. runtests.jl is the script used to launch tests (it's the script that Pkg.test() runs), and the design of ReTestItems.jl is for no @testitems live in this file.

Intended usage would look like

% cat test/runtests.jl 
using ReTestItems
runtests()
% cat test/example_tests.jl 
@testitem "Example tests" begin
    error("Fail")
end

@kenahoo
Copy link
Author

kenahoo commented Sep 5, 2024

Aha, thanks. I indeed get better luck with that setup.

It does seem like something, somewhere, should be noticing that tests failed under the setup I had, though - is that Test.jl maybe?

@nickrobinson251
Copy link
Collaborator

hmmm, yeah, good point

Does this branch give you the behaviour you expect: #178 ?

You can try it out if using Pkg.add(name="ReTestItems", rev="npr-propogate-test-error")

@kenahoo
Copy link
Author

kenahoo commented Sep 5, 2024

For some reason I can't seem to try that out, I keep getting ERROR: can not merge projects when I try to run tests with that branch installed. I did some googling about the issue but couldn't find a solution.

@nickrobinson251
Copy link
Collaborator

looks like a known issue with using test/Project.toml files (in general i'd advise against doing that)
https://discourse.julialang.org/t/can-not-merge-projects-error-when-dev-ing-sister-package-from-test-project/115575/3?

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

Successfully merging a pull request may close this issue.

2 participants