I’ve been tring to get started with a basic Pytest internal app plugin. According to the v8.1.1 Pytest doc, loading MyPlugin.py
in a test_TestPlugin.py
file should be possible with pytest_plugins = ["MyPlugin",]
in said test_ file. However, running pytest -s
gives an ImportError: “No module named ‘MyPlugin'”.
Both plugin & test_ file are located in the same tests/
directory.
MyPlugin.py
:
import pytest
@pytest.hookimpl()
def pytest_runtest_setup(item:pytest.Item):
print("Hook executed!")
test_TestPlugin.py
:
pytest_plugins = ["MyPlugin",]
def test_quick():
assert 1 == 1
I’ve tried:
- Putting
pytest_plugins
in conftest.py instead. Gives same ImportError. - Prepending “MyPlugin” with the directory both plugin and test_ file are in:
pytest_plugins = ["tests.MyPlugin",]
. This DOES work, however is not expected nor prefered.
Any and all help is appreciated!
New contributor
Rosevb is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.