I have a bunch of tests written using pytest. There are all under a directory dir
. For example:
dir/test_base.py
dir/test_something.py
dir/test_something2.py
...
The simplified version of code in them is as follows:
test_base.py
import pytest
class TestBase:
def setup_module(module):
assert False
def teardown_module(module):
assert False
test_something.py
import pytest
from test_base import TestBase
class TestSomething(TestBase):
def test_dummy():
pass
test_something2.py
import pytest
from test_base import TestBase
class TestSomethingElse(TestBase):
def test_dummy2():
pass
All my test_something*.py
files extend the base class in test_base.py
. Now I wrote setup_module(module)
and teardown_module(module)
methods in test_base.py
. I was expecting the setup_module to be called once for all tests, and teardown_module()
to be called at the end, once all tests are finished.
But the functions don’t seem to be getting called? Do I need some decorators for this to work?