Create a test fixture file
Description
A test fixture file contains a class similar to ‘TestBase’ class (reference in Create a test base file). However, it includes ‘setup’ and ‘teardown’ methods that are called multiple times during the test execution, rather than just at the beginning and end.
You can create test fixtures specific to individual test series within their respective folders, in addition to the global test fixture file ‘Global_name_test_fixture.py’, within the project directory as shown in the Project structure.
The ‘NameTestFixture’ class should follow this format:
from Tests.NameTestBase import NameTestBase
class NameTestFixture(TutoTestBase):
# test fixture precondition, executed before testcase setUp
@classmethod
def setUpClass(cls):
pass # setup logic goes here
# test fixture cleanup, executed after testcase tearDown
@classmethod
def tearDownClass(cls):
pass # teardown logic goes here
Once the fixture is prepared, you can import it using a relative import into the desired test case and inherit from it.
from .my_project import NameTestFixture