- conftest
Add extra command line parameters to Pytest - used in the autouse fixtures
examples/pytest/py4/conftest.py
#import pytest # def pytest_addoption(parser): parser.addoption("--demo") # #@pytest.fixture #def demo(request): # return request.config.getoption("--demo")
examples/pytest/py4/test_one.py
import pytest @pytest.fixture(autouse = True, scope="module") def module_demo(request): demo = request.config.getoption("--demo") print(f"Module {demo}") return demo @pytest.fixture(autouse = True, scope="function") def func_demo(request): demo = request.config.getoption("--demo") print(f"Func {demo}") return demo def test_me(): pass def test_two(): pass
pytest -s --demo Hello Module Hello Func Hello Func Hello