blissdata: allow testing outside conda environment
This MR allows for optional pytest arguments
pytest --redis-module-dir=/my/module/dir \
--redis-config-file=/my/redis/redis.conf \
--redis-exec=/my/redis/server \ # we already had this one
./blissdata
Motivation
- Allow testing without conda. For example https://gitlab.esrf.fr/bliss/blissdata/-/merge_requests/11.
- Other projects which depend on blissdata need tests with a blissdata-compliant redis server. For example https://gitlab.esrf.fr/bliss/blissoda. Re-using the fixture from blissdata helps. Of course none of those projects do conda.
pytest --pyargs blissdata.tests
Will not work with Because of https://github.com/pytest-dev/pytest/issues/1596 these arguments are currently not available when running tests with --pyargs
(runs the tests of the installed package, not the source directory). For example instead of
pytest -v --pyargs blissdata.tests --redis-config-file=/etc/redis/redis.conf
you will need to do
export TEST_WD=$(python -c "from blissdata import tests;print(tests.__path__[0])")
pytest -v --redis-config-file=/etc/redis/redis.conf $TEST_WD
In the Bliss CI case (which has CONDA_PREFIX) you don't needs redis arguments so this works as expected
pytest -v --pyargs blissdata.tests
Details of MR
Since we are forced to launch our own redis server because pytest-redis
does not support loadmodule
, the pytest-redis
dependency is overkill and the fixture factory is also awkward (arguments are needed upon import, which means finding a free port upon import). So imo we can drop pytest-redis
.
I also intend to reuse the redis_db
in other projects that need blissdata
testing with the redis modules (e.g. blissoda). Hence I defined everything in a separate module blissdata.tests.redis_server
. Usage would be
# conftest.py of blissoda for example
from blissdata.tests.redis_server import add_redis_server_options
from blissdata.tests.redis_server import redis_db # noqa F401
def pytest_addoption(parser):
add_redis_server_options(parser)