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

@setup and @teardown blocks #20

Open
ssfrr opened this issue Jun 28, 2014 · 3 comments
Open

@setup and @teardown blocks #20

ssfrr opened this issue Jun 28, 2014 · 3 comments

Comments

@ssfrr
Copy link

ssfrr commented Jun 28, 2014

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
Copy link
Author

ssfrr commented Jun 28, 2014

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
Copy link
Contributor

IainNZ commented Nov 4, 2014

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
Copy link

pdobacz commented Aug 27, 2016

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?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants