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

Unable to test warnings with \@test_logs #183

Closed
AshlinHarris opened this issue Aug 16, 2022 · 2 comments · Fixed by #190
Closed

Unable to test warnings with \@test_logs #183

AshlinHarris opened this issue Aug 16, 2022 · 2 comments · Fixed by #190

Comments

@AshlinHarris
Copy link
Contributor

julia> @test_logs (:warn, "This DataFrame is large. Computation may take a while.") add_label_column!(df, df2, :b)
Log Test Failed at REPL[47]:1
  Expression: add_label_column!(df, df2, :b)
  Log Pattern: (:warn, "This DataFrame is large. Computation may take a while.")
  Captured Logs:
    Test.LogRecord(Warn, "This DataFrame is large. Computation may take a while.", PreprocessMD, :PreprocessMD, :PreprocessMD_172387a5, "\\\\files.brown.edu\\Home\\aharri69\\Desktop\\GitHub\\PreprocessMD\\src\\PreprocessMD.jl", 270, Base.Pairs{Symbol, Union{}, Tuple{}, NamedTuple{(), Tuple{}}}())
    Test.LogRecord(Warn, "This DataFrame is large. Computation may take a while.", PreprocessMD, :PreprocessMD, :PreprocessMD_172387a5, "\\\\files.brown.edu\\Home\\aharri69\\Desktop\\GitHub\\PreprocessMD\\src\\PreprocessMD.jl", 270, Base.Pairs{Symbol, Union{}, Tuple{}, NamedTuple{(), Tuple{}}}())

ERROR: There was an error during testing

The warning should be detected, since @test_nowarn fails for the same function call. The example test from the documentation works, so I wonder if it has to do with add_label_column! being inside a package module.

https://docs.julialang.org/en/v1/stdlib/Test/#Test.@test_logs

@AshlinHarris
Copy link
Contributor Author

I've tried using :Warn instead of :warn, as well as changing the warning to an @info message, like in the example.

@AshlinHarris
Copy link
Contributor Author

As a workaround, I am using match_mode=:any, since I can't find any way to match patterns if the test is being called from withing PreprocessMD.

@AshlinHarris AshlinHarris linked a pull request Aug 18, 2022 that will close this issue
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.

1 participant