Search code examples
pythondockermacostox

How to install dependencies that are installed in a tox-docker container, but NOT locally?


I'd like to execute unit test (configured in tox.ini) in a docker container using tox-docker plugin. The idea behind it is to be able run unit tests, that require cuda-python module, on a MacBook with Apple M2 Pro. My question is - how should I configure a corresponding section in a tox.ini so that the requirements are installed in a docker container, but not locally (because this would fail)?

Here is mentioned section in a tox.ini:

[testenv:test-docker-env]
docker =
    py-3.11
skip_install = false
deps =
    # -r{toxinidir}/requirements/requirements.txt     # <- this fails when executed locally on MacBook!
    -r{toxinidir}/requirements/requirements-test.txt
commands =
    python -m pytest --cov=src \
        --cov-report term-missing \
        --cov-report xml:coverage-reports/coverage-BUILD_{env:BUILD_NUMBER:0}.xml \
        --junitxml=xunit-reports/xunit-result-BUILD_{env:BUILD_NUMBER:0}.xml \
        -vv \
        tests/

[docker:py-3.11]
image = python:3.11

How can i instruct tox-docker to install required modules from the {toxinidir}/requirements/requirements.txt, but not let tox to install them locally?


Solution

  • I don't believe a plugin could instruct tox to install some dependencies but not other; tox just installs locally whatever it sees in tox.ini. So I think you need to remove non-local dependencies from tox.ini and install them in a Dockerfile.