tox-dev / tox-docker

A tox plugin to run one or more Docker containers during tests

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Unable to run containers with Python versions that are not installed in the host

Corvan opened this issue · comments

This is my tox.ini:

[tox]
deps =
    black
    dataclasses_json
    httpx
    respx
    git+https://github.com/tox-dev/tox-docker@build-then-use-image#egg=build-then-use-image

#skip_missing_interpreters = false
envlist =
    py{39,310,311}-{black,lint,mypy,unittest}
isolated_build = true

[testenv]
passenv=PYTHONPATH

[testenv:py39-black]
docker = black39

[testenv:py310-black]
docker = black310

[testenv:py311-black]
docker = black311

[testenv:py{39,310,311}-black]
allowlist_externals =
    black
commands = black --check .

[testenv:py39-lint]
docker = lint39

[testenv:py310-lint]
docker = lint310

[testenv:py311-lint]
docker = lint311

[testenv:py{39,310,311}-lint]
requires = ruff
allowlist_externals =
    ruff
commands = ruff check mailpit

[testenv:py39-mypy]
docker = mypy39

[testenv:py310-mypy]
docker = mypy310

[testenv:py311-mypy]
docker = lint311

[testenv:py{39,310,311}-mypy]
requires =
    mypy
allowlist_externals =
    mypy
commands = mypy mailpit

[testenv:py39-unittest]
docker = unittest39

[testenv:py310-unittest]
docker = unittest310

[testenv:py311-unittest]
docker = unittest311

[testenv:py{39,310,311}-unittest]
deps =
    dataclasses_json
    httpx
    respx
allowlist_externals =
    dataclasses_json
    httpx
    respx
commands =  python -m unittest discover -s tests/unit

[docker:black39]
dockerfile = {toxinidir}/tests/docker/python/3.9/black.Dockerfile

[docker:black310]
dockerfile = {toxinidir}/tests/docker/python/3.10/black.Dockerfile

[docker:black311]
dockerfile = {toxinidir}/tests/docker/python/3.11/black.Dockerfile

[docker:lint39]
dockerfile = {toxinidir}/tests/docker/python/3.9/lint.Dockerfile

[docker:lint310]
dockerfile = {toxinidir}/tests/docker/python/3.10/lint.Dockerfile

[docker:lint311]
dockerfile = {toxinidir}/tests/docker/python/3.11/lint.Dockerfile

[docker:mypy39]
dockerfile = {toxinidir}/tests/docker/python/3.9/mypy.Dockerfile

[docker:mypy310]
dockerfile = {toxinidir}/tests/docker/python/3.10/mypy.Dockerfile

[docker:mypy311]
dockerfile = {toxinidir}/tests/docker/python/3.11/mypy.Dockerfile

[docker:unittest39]
dockerfile = {toxinidir}/tests/docker/python/3.9/unittest.Dockerfile

[docker:unittest310]
dockerfile = {toxinidir}/tests/docker/python/3.10/unittest.Dockerfile

[docker:unittest311]
dockerfile = {toxinidir}/tests/docker/python/3.11/unittest.Dockerfile

And the relevant output is:

py39-black: skipped because could not find python interpreter with spec(s): py39
py39-black: SKIP ⚠ in 0.01 seconds
py39-lint: skipped because could not find python interpreter with spec(s): py39
py39-lint: SKIP ⚠ in 0 seconds
py39-mypy: skipped because could not find python interpreter with spec(s): py39
py39-mypy: SKIP ⚠ in 0 seconds
py39-unittest: skipped because could not find python interpreter with spec(s): py39
py39-unittest: SKIP ⚠ in 0 seconds

This is on Ubuntu 22.10 where only python3.10 and python3.11 are available.

Did I miss something? Or did I do something wrong?
By the way: The dockerfile building feature of #156 works very well.

This is not an issue with tox-docker, I think you are running into tox's python version inference, which is explained at https://tox.wiki/en/latest/config.html#base_python and a few other places in the documentation. The py39, etc, part of the names is what is triggering this.

I think this would work if you named your testenvs slightly differently.

Please also note that tox-docker isn't for "run my tests in this docker container," it's for "have this docker container available when my tests run in tox" -- use cases like having a database or other service alongside your python code. (I can't actually tell if that's what you're trying to do here or not in this example)