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

Macro in test undefined #3

Closed
itsdfish opened this issue Apr 18, 2020 · 3 comments · May be fixed by #16
Closed

Macro in test undefined #3

itsdfish opened this issue Apr 18, 2020 · 3 comments · May be fixed by #16

Comments

@itsdfish
Copy link

Hi-

I want to report that SafeTestsets cannot find the model macro in Turing.jl. Here is a MWE:

using SafeTestsets

@safetestset "test" begin 
    using Turing, Test

    @model model() = begin

    end

end

Error:

LoadError: UndefVarError: @model not defined
in expression starting at untitled-9ab27cc42abe98b4171bec7361504afa:6
in top-level scope at SafeTestsets/A83XK/src/SafeTestsets.jl:23
in eval at base/boot.jl:331
in top-level scope at 

Version

(@v1.4) pkg> st Turing
Status `~/.julia/environments/v1.4/Project.toml`
  [fce5fe82] Turing v0.11.0
(@v1.4) pkg> st SafeTestsets
Status `~/.julia/environments/v1.4/Project.toml`
  [1bc83da4] SafeTestsets v0.0.1

By the way, thank you for putting this package together. I find it to be very useful.

@YingboMa
Copy link
Owner

Thanks for reporting the issue. Sorry for the late response. I am not good at keeping track of my GitHub notifications. The problem here is that by the time @safetestset macro expands, Turing isn't loaded yet, so there is the UndefVarError: @model not defined error.

@safetestset is designed to use with include, so you won't have this problem.

@YingboMa
Copy link
Owner

Macros won't work in this case in general, so this issue cannot be fixed.

julia> @time begin
           using Turing, Test

           @model model() = begin

           end
       end
ERROR: LoadError: UndefVarError: @model not defined
Stacktrace:
 [1] top-level scope
 [2] eval(::Module, ::Any) at ./boot.jl:331
 [3] eval_user_input(::Any, ::REPL.REPLBackend) at /buildworker/worker/package_linux64/build/usr/share/julia/stdlib/v1.4/REPL/src/REPL.jl:86
 [4] run_backend(::REPL.REPLBackend) at /home/scheme/.julia/packages/Revise/AMRie/src/Revise.jl:1023
 [5] top-level scope at none:0
in expression starting at REPL[1]:4

@musoke
Copy link

musoke commented Oct 15, 2020

@safetestset is designed to use with include, so you won't have this problem.

It would be nice to be able to use it with @nbinclude too, but it isn't too hard to just write out a module by hand.

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.

3 participants