You can also use x-unit style for setups and teardowns:
def setup_method(self, method):
def teardown_method(self, method):
assert 1 == 1
When I run this test, the following will be printed:
You can see that when you run it with -s option:
$ pytest -s.
I think the methods are pretty self-explanatory, but it really does this:
- setup_class: runs once before all test cases
- teardown_class: runs once after all test cases
- setup_method: runs before every test case in the class
- teardown_method: runs after every test case in the class
I think fixtures are a bit more powerful, but this is perhaps a bit more readable and understandable than decorators which might not be easy to understand when you see it for the first time.