August 2018
Beginner
160 pages
4h 8m
English
The first thing we should do is to extract the desired functionality into well-defined fixtures and put them into a conftest.py file. Continuing with our example, we can create db_testing and gui_testing fixtures:
class DataBaseFixture: def __init__(self): self.db_file = self.create_temporary_db() self.session = self.connect_db(self.db_file) def teardown(self): self.session.close() os.remove(self.db_file) def create_temporary_db(self): ... def connect_db(self, db_file): ... ...@pytest.fixturedef db_testing(): fixture = DataBaseFixture() yield fixture fixture.teardown()class GUIFixture: def __init__(self): self.app = self.create_app() def teardown(self): self.app.close_all_windows() def mouse_click(self, window, ...
Read now
Unlock full access