Framework Mode - Marker registration
Folder Structure
test_project/
├── tests/
│ ├── test_login.py
│ ├── test_registration.py
│ └── test_payment.py
├── pytest.ini
├── conftest.py
└── utils/
└── helpers.py
test_project/
├── tests/
│ ├── test_login.py
│ ├── test_registration.py
│ └── test_payment.py
├── pytest.ini
├── conftest.py
└── utils/
└── helpers.py
tests/ folder, contain test functions using pytest markers to categorize tests.pytest.ini file registers custom markers and sets pytest options.conftest.py defines fixtures and hooks used across tests.utils/ folder.The pytest.ini file is used to register custom markers to avoid warnings and enable marker-based test selection.
[pytest]
markers =
smoke: mark a test as a smoke test
regression: mark a test as a regression test
slow: mark a test as slow running
Use command line options to run tests by marker, e.g., pytest -m smoke.
conftest.py can define fixtures that tests with markers can use.
--junitxml=report.xml to generate XML reports for CI tools.smoke tests on pull requests.pytest.ini to avoid warnings and improve clarity.smoke, regression, slow).Where in this folder structure would you add a new marker called api to categorize API tests?
pytest.ini?pytest.ini to inform pytest about custom markers.slow in pytest.ini?pytest.ini content and test code, what will be the result when running pytest -m slow?
[pytest] markers = slow: marks tests as slow
import pytest
@pytest.mark.slow
def test_example():
assert True
def test_fast():
assert True
-m slow option-m slow option runs only tests marked with @pytest.mark.slow.test_example is marked with @pytest.mark.slow, test_fast is not.database to your tests but pytest shows a warning: PytestUnknownMarkWarning. What is the most likely cause and how to fix it?pytest.ini.database marker under the [pytest] section in pytest.ini to register it and remove the warning.api but skip those marked as slow. Your pytest.ini contains:
[pytest]
markers =
api: marks API tests
slow: marks slow tests
Which command correctly runs only api tests excluding slow tests?-m option accepts boolean expressions combining markers using and, or, and not.api but not slow, so expression is api and not slow.Pass the test and this pattern moves unknown