Pytest unittest-style setup: module setup
Question:
Pytest documentation describes four ways to setup/teardown things:
- module level setup/teardown
- class level setup/teardown
- method level setup/teardown
- function level setup/teardown
But in one project it was implemented like this:
class TestClass:
def setup(self):
...
def test_1(self):
...
...
This setup method is called around each method invocation, just like setup_method from documentation (except that it doesn’t take method as an argument). But I haven’t seen it in the documentation or anywhere else. Why does it work?
Answers:
Check this code
https://pytest.org/latest/_modules/_pytest/python.html
I would guess it’s inheriting and using
def setup(self):
It’s part of nose testing framework which is integrated in pytest. More information you can find here
Pytest documentation describes four ways to setup/teardown things:
- module level setup/teardown
- class level setup/teardown
- method level setup/teardown
- function level setup/teardown
But in one project it was implemented like this:
class TestClass:
def setup(self):
...
def test_1(self):
...
...
This setup method is called around each method invocation, just like setup_method from documentation (except that it doesn’t take method as an argument). But I haven’t seen it in the documentation or anywhere else. Why does it work?
Check this code
https://pytest.org/latest/_modules/_pytest/python.html
I would guess it’s inheriting and using
def setup(self):
It’s part of nose testing framework which is integrated in pytest. More information you can find here