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

Global before.each #79

Open
raindrift opened this issue Apr 27, 2016 · 7 comments
Open

Global before.each #79

raindrift opened this issue Apr 27, 2016 · 7 comments
Milestone

Comments

@raindrift
Copy link

raindrift commented Apr 27, 2016

It'd be wonderful to be able to define a before.each for the entire suite. This would allow things like ensuring that the database is always cleared between examples. As it is, I have to do the global test setup once per file.

With RSpec, which seems to be what mamba is modeled on, you can put before(:each) and before(:all) in the global rspec configuration.

@nestorsalceda
Copy link
Owner

Hey @raindrift!

Mamba provides a before.all hook on every suite. Do you refer to all suites or with this hook is enough?

Thanks!

@raindrift
Copy link
Author

raindrift commented Apr 27, 2016

I know about the hooks. What I'm wondering is, can I have a before.all or a before.each on the entire test suite?

For example, let's say I have a spec/ directory with six spec files. Right now, I'm doing the following in each file:

from spec.helper import *
from myproject import mymodule

with description('mymodule'):
    with before.each:
        setup(self)

Then, spec.helper implements a setup() function that sets up a connection to my test database, clears the db, etc.

I'd love to remove that chunk of boilerplate from all my tests, though. It'd be great if there was some global configuration where I could specify these things. It'd make the test files cleaner, and reduce the chance that I'll forget to call it.

@jes5e
Copy link
Contributor

jes5e commented Dec 9, 2017

+1

@nestorsalceda
Copy link
Owner

Oookey, I see :)

It's something like before/after hooks in configuration, like RSpec ones: https://relishapp.com/rspec/rspec-core/v/3-7/docs/hooks/before-and-after-hooks#define-%60before%60-and-%60after%60-blocks-in-configuration

And when we have tagging support, i thing this idea would be useful too: https://relishapp.com/rspec/rspec-core/v/3-7/docs/hooks/when-first-matching-example-defined-hook

Thanks for the idea, I would consider it for 1.0 release :)

@MatthewRalston
Copy link

Thanks for considering this @nestorsalceda

@danilito19
Copy link

@nestorsalceda will this feature be added anytime soon? Considering migrating from pytest > mamba, but having a global fixture (defining it only once) that runs for every single "it" block in my entire testing directory is essential.

@nestorsalceda nestorsalceda added this to the 0.11.0 milestone Apr 13, 2020
@nestorsalceda
Copy link
Owner

Yes, I think is easy to implement. I have some doubts about how to share state between the specs, but I think it can be done easily.

I'm going to target it to next week release :)

@nestorsalceda nestorsalceda modified the milestones: 0.11.0, 0.12.0 Apr 26, 2020
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

No branches or pull requests

5 participants