We have a lot of repeated tests for many applications (testinfra). I want to create BaseClass to be inherited by app-specific test classes to reduce boilerplate of repeated tests (is this service running? is this port listen?).
We have tests in a structure like this /tests/{app-name}/test_{app_name}.py. There is /tests/conftest.py file with pytest fixtures.
I'm trying to find a way to put BaseClass somewhere in conftest.py or near it and to be able import it.
The problems:
- tests are run in CI and I don't want to install any modules/packages (that means I can't just
pip installmodule with BaseClass and thanfrom thismodule import BaseClass) - Due to convention we must use dashes in
{app-name}. That beaks all relative imports asapp-nameis not a package for python, even there if__init__.pyis present.
Is any reasonable way to load class from a specific file, or get it for free (magic at collection time) from pytest?