PyTest conftest
Introduction
In this article you can get acquainted with the use of the conftest.py file in PyTest.
It is assumed that you are already familiar with the article
@fixtures
Official documentation
Command-line arguments
Let us look at the simplest test that expects an argument from the command line.
Project structure:
demo/ ├── conftest.py └── demo_test.py
def test_name(site_url): print(site_url) assert isinstance(site_url, str)
# conftest.py import pytest def pytest_addoption(parser): parser.addoption("--site-url", action="store", default=None) @pytest.fixture def site_url(request): return request.config.getoption("--site-url")
python -m pytest -sv --site-url devhops.ru .\demo\demo_test.py
================================= test session starts ================================= … collected 1 item demo/demo_test.py::test_name devhops.ru PASSED ================================== 1 passed in 0.04s ==================================
Article author: Arthur Isaev