I am building a package that provides (1) a fixed interface with (2) pluggable drivers. The desired driver will be selectable by the user of the package. My package will include at least one driver with it, but I would like other developers to be able to implement and validate drivers that conform to the package's interface. As such, I would like these developers to be able to run my tests against their drivers.
Currently, I am using py.test's parametrized fixtures to inject my driver(s) into my tests:
# conftest.py
import my_pkg
import pytest
@pytest.fixture(params=[my_pkg.MyDriver])
def driver(request):
return request.param
# my_pkg/tests/conftest.py
import my_pkg
import pytest
@pytest.fixture
def my_interface(driver):
return my_pkg.MyInterface(driver)
# my_pkg/tests/test_my_interface.py
def test_that_it_does_the_right_thing(my_interface):
assert my_interface.some_method() == "some return value"
I structured it this way in the hopes that someone would be able to collect and run my tests against their version of the driver fixture. In other words, their package would look something like this:
# setup.py
from setuptools import setup
setup(
# ...
install_requires=["my-pkg"])
# conftest.py
import their_pkg
import pytest
@pytest.fixture(params=[their_pkg.TheirDriver])
def driver(request):
return request.param
Obviously this is not enough to get it to work, because py.test doesn't appear to offer an option to inject tests from external packages. But how, if at all, is this possible?
(This question seems to be conceptually similar, but the author appears to be working entirely within one codebase. I would like a completely separate pip-installed package to be able to reference tests included in my pip-installed package.)