Framework Mode - Fixture factories
Folder Structure
tests/ ├── test_user.py ├── test_order.py ├── conftest.py utils/ ├── data_factories.py ├── helpers.py
tests/ ├── test_user.py ├── test_order.py ├── conftest.py utils/ ├── data_factories.py ├── helpers.py
utils/data_factories.py, this layer contains factory functions that create test data objects or test fixtures dynamically.conftest.py, it uses fixture factories to provide reusable test data or setup for tests.tests/ folder use fixtures to run test cases.utils/helpers.py support test logic and data creation.pytest.ini to select test environment (dev, staging, prod).pytest command line options or config files to select browsers or service endpoints.pytest built-in reporting with options like --junitxml=report.xml for CI systems.pytest-html for readable HTML reports.conftest.py fixtures to avoid duplication.Where in this framework structure would you add a new fixture factory for creating Product test data objects?
@pytest.fixture
def user_factory():
def create_user(name):
return {'name': name, 'active': True}
return create_user
def test_user_active(user_factory):
user = user_factory('Alice')
assert user['active'] is True
@pytest.fixture
def product_factory():
def create_product(name, price):
return {'name': name, 'price': price}
return create_product
def test_product(product_factory):
product = product_factory('Book')
assert product['price'] > 0
Pass the test and this pattern moves unknown