Reputation: 1243
I have several packages I want to to write pytest
tests for. All the packages should use same fixture logic, so I want to have the common test logic (fixtures) to sit in some common path and each package test should reside in its own path.
Repository 1:
=============
/path/to/PackageA/test_A.py
/path/to/PackageB/test_B.py
Repository 2:
=============
/different_path/to/Common/conftest.py
The problem is that when I run pytest
on test_A.py
or test_B.py
, pytest
doesn't find fixtures defined in conftest.py
.
Tried to play with --confcutdir
option, but with no luck...
The only scenario that is working for me is running pytest
from /different_path/to/Common/
, while setting pytest.ini
testpath = /path/to/PackageA/
(BTW running pytest /path/to/PackageA/
didn't work).
Upvotes: 3
Views: 467
Reputation: 15345
The answer to that problem is to transform Common
into a pytest plugin. If you already have a setup.py
for that Common
project, it is just a matter of adding this to your setup
call:
# the following makes a plugin available to pytest
entry_points = {
'pytest11': [
'common = Common.plugin',
]
},
You will have to rename Common/conftest.py
to plugin.py
though (or something else other than conftest.py
), as py.test treats that file name specially.
If you don't have a setup.py
for Common
, then you can make py.test use it as a plugin by adding addopts = -p Common.plugin
to PackageA/pytest.ini
and PackageB/pytest.ini
.
Upvotes: 2