Skip to content

Commit

Permalink
tox.ini: Fix Python environment factors
Browse files Browse the repository at this point in the history
Tox's default nomenclature for referring to Python test environments
(without further config options) follows the 'py3[[:digit:]]*'
expression, in other words if one wants to run tests against Python
3.9, they'd put 'py39' in the 'envlist' setting, similarly for py310,
py311, etc.

We didn't follow the rules and so we always executed tox against the
Python version that was originally used to create the development
virtual environment. This is proved by the tox's output which reports:

    python3.10: install_deps> python -I -m pip install -r
        requirements-extras.txt
    ...
    ===========================================================
    platform linux -- Python 3.11.5, pytest-7.4.2, pluggy-1.3.0

despite having been instructed (though in an incorrect way) to run a
Python 3.10 environment. This behaviour also silently ignored cases
where the given Python version wasn't even installed on the system, so
the platform Python which was used to create the virtual environment
was always used.

After this patch, this is what the execution reports:

    py310: install_deps> python -I -m pip install -r
        requirements-extras.txt
    .pkg-cpython310: install_requires> python -I -m pip install
        setuptools setuptools-scm
    ...
    ============================================================
    platform linux -- Python 3.10.13, pytest-7.4.2, pluggy-1.3.0

AND

    py310: skipped because could not find python interpreter with
        spec(s): py310

if python3.10 isn't installed on the host system.

While at it, use Bash-like brace expansion to cover a range of minor
Python 3 versions instead of explicitly enumerating each one of them.

Signed-off-by: Erik Skultety <[email protected]>
  • Loading branch information
eskultety authored and chmeliik committed Oct 12, 2023
1 parent 8f293f4 commit 80aecd8
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 12 deletions.
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
PYTHON_VERSION_VENV ?= python3.9
TOX_ENVLIST ?= python3.9
TOX_ENVLIST ?= py39
TOX_ARGS ?=

all: venv
Expand Down
10 changes: 5 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -197,21 +197,21 @@ For finer control over which tests get executed, e.g. to run all tests in a spec
the [virtualenv](#virtualenv) and run:

```shell
tox -e python3.9 -- tests/unit/test_cli.py
tox -e py39 -- tests/unit/test_cli.py
```

Even better, run it stepwise (exit on first failure, re-start from the failed test next time):

```shell
tox -e python3.9 -- tests/unit/test_cli.py --stepwise
tox -e py39 -- tests/unit/test_cli.py --stepwise
```

You can also run a single test class or a single test method:

```shell
tox -e python3.9 -- tests/unit/test_cli.py::TestGenerateEnv
tox -e python3.9 -- tests/unit/test_cli.py::TestGenerateEnv::test_invalid_format
tox -e python3.9 -- tests/unit/extras/test_envfile.py::test_cannot_determine_format
tox -e py39 -- tests/unit/test_cli.py::TestGenerateEnv
tox -e py39 -- tests/unit/test_cli.py::TestGenerateEnv::test_invalid_format
tox -e py39 -- tests/unit/extras/test_envfile.py::test_cannot_determine_format
```

In short, tox passes all arguments to the right of `--` directly to pytest.
Expand Down
10 changes: 4 additions & 6 deletions tox.ini
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,7 @@ envlist =
black
isort
mypy
python3.9
python3.10
python3.11
py3{9,10,11}

[testenv]
passenv =
Expand Down Expand Up @@ -74,9 +72,9 @@ skipsdist = true

[gh-actions]
python =
3.9: python3.9
3.10: python3.10
3.11: python3.11
3.9: py39
3.10: py310
3.11: py311

[flake8]
show-source = True
Expand Down

0 comments on commit 80aecd8

Please sign in to comment.