JuliaAttic / FactCheck.jl

Midje-like testing for Julia
Other
81 stars 36 forks source link

@setup and @teardown blocks #20

Open ssfrr opened 10 years ago

ssfrr commented 10 years ago

Often a set of tests has some common setup and teardown code you want to run for each test. It would be great to be able to do something like:

module TestMyModule
@setup begin
    obj = SomeObj()
    obj.times_called = 0
end

facts() do
    # setup block runs here
    run_my_func(obj)
    @fact obj.times_called = 1
    # teardown block runs here
end

end # module TestMyModule

I think that it would make sense that @setup block defined at the module scope would be run for each facts block, and @setup defined inside a facts block would apply to each context

ssfrr commented 10 years ago

I should also note that it feels a little sketchy for the @setup and @teardown blocks to just get pasted into the fact body. One option would be to have the testing do block take an argument that has any testing environment created by @setup

IainNZ commented 10 years ago

I'm going to tag this one as "up for grabs" because I feel a lot of macro magics are required to make this work well, and a similar effect can be achieved with just good old-fashioned functions.

pdobacz commented 8 years ago

A question: have you considered doing the setup/teardown in pytest fixtures style.? I am using pytest a lot now, and after a moment of getting used to I grew very fond of this approach.

BTW, do you have any knowledge of any testing framework for Julia that would try to mimic pytest's idea?