I would like to set up a fixture in conftest.py and share it with all my tests. However, I run into the following error when running pytest on the following minimal example:
ERROR at setup of test_test
Fixture "pytest_runtest_setup" called directly. Fixtures are not meant to be called directly,
but are created automatically when test functions request them as parameters.
conftest.py
import pytest
import os
@pytest.fixture
def pytest_runtest_setup():
print("hello ? ---------------------------------")
test.py
import pytest
def test_test():
assert True
pytest.ini
[pytest]
addopts = -rA -v -p no:faulthandler -W ignore::DeprecationWarning
Pytest launched with pytest test.py
Nowhere is the fixture function called directly, it is not even used in the sample test. So why is pytest throwing this and how can I declare and use fixtures into conftest.py?
Env:
- Python 3.8.3
- pytest-6.1.2