Framework Mode - Fixture dependencies (fixture using fixture)
Folder Structure
project-root/ ├── tests/ │ ├── test_example.py │ └── conftest.py ├── src/ │ └── app_code.py ├── pytest.ini └── requirements.txt
project-root/ ├── tests/ │ ├── test_example.py │ └── conftest.py ├── src/ │ └── app_code.py ├── pytest.ini └── requirements.txt
conftest.py, fixtures can depend on other fixtures to share setup logic.tests/ use fixtures by declaring them as function parameters.src/ folder contains the main application code under test.pytest.ini holds pytest configuration options.Use pytest.ini or tox.ini to configure pytest options like markers and test paths.
Manage environment variables or secrets outside code, e.g., with .env files or CI environment settings.
Fixtures can accept parameters or use pytest_addoption to handle different environments or browsers.
pytest-html or pytest-cov for HTML reports and coverage.pytest --junitxml=report.xml.function, module, or session scopes to optimize test speed.autouse sparingly: Only when you want fixtures to run automatically without explicit use.Where in this folder structure would you add a new fixture that depends on an existing database connection fixture?
import pytest
@pytest.fixture
def base():
return 10
@pytest.fixture
def add_five(base):
return base + 5
def test_sum(add_five):
assert add_five == 15
print(add_five)import pytest
@pytest.fixture
def data():
return [1, 2, 3]
@pytest.fixture
def processed_data():
data.append(4)
return datafull_config that depends on two other fixtures: base_config returning a dict {'host': 'localhost'} and auth_config returning {'user': 'admin'}. Which code correctly combines these fixtures so full_config returns {'host': 'localhost', 'user': 'admin'}?Pass the test and this pattern moves unknown