Framework Mode - Registering markers in pytest.ini
Folder Structure
project-root/
├── tests/
│ ├── test_login.py
│ ├── test_registration.py
│ └── test_profile.py
├── pytest.ini
├── conftest.py
└── utils/
└── helpers.py
project-root/
├── tests/
│ ├── test_login.py
│ ├── test_registration.py
│ └── test_profile.py
├── pytest.ini
├── conftest.py
└── utils/
└── helpers.py
pytest.ini file where markers are registered and test settings are defined.tests/ folder containing test files using markers to categorize tests.conftest.py for shared fixtures and hooks.utils/ folder for helper functions and reusable code.The pytest.ini file is used to register custom markers to avoid warnings and improve test organization.
[pytest]
markers =
smoke: Quick smoke tests
regression: Full regression tests
slow: Tests that take longer time
This file also configures other pytest options like test paths or addopts.
Markers help filter tests in CI pipelines, e.g., run only smoke tests on every commit.
Example CI command to run smoke tests only:
pytest -m smoke --junitxml=reports/smoke-results.xml
Reports can be integrated with CI tools like Jenkins, GitHub Actions, or GitLab CI for pass/fail status and test details.
pytest.ini to avoid warnings and document their purpose.pytest.ini simple and focused on configuration only.Where in this framework structure would you add a new marker called api for tests that target API endpoints?
pytest.ini file?pytest.ini prevents warnings about unknown markers and keeps tests organized.slow in pytest.ini?[markers] section in pytest.ini.= with a description, e.g., slow = marks tests as slow.pytest.ini content:
[markers] api = marks tests as api tests slow = marks tests as slowWhat happens if you run
pytest -m slow?-m option runs tests matching the given marker name.slow is registered and used, pytest -m slow runs only tests marked with @pytest.mark.slow.pytest.ini:
[markers] fast marks tests as fastBut when running tests, pytest shows a warning about unknown marker 'fast'. What is the problem?
= between the marker name and its description.fast marks tests as fast lacks '=', so pytest treats 'fast' as unknown marker.pytest.ini: db for database tests and ui for user interface tests. Which pytest.ini content correctly registers both markers?[markers] section, not [pytest].= with a description, e.g., db = marks tests as database tests.db and ui markers are listed on separate lines with descriptions.Pass the test and this pattern moves unknown