Search code examples
pythontox

How to create 2 environments in tox with different library version


I need to test my library on the same python version but different dependent package version using tox. I have tried this:

[tox]
requires =
    tox>=4
env_list = py{37,38,39,310,311,typeguard_{v2,v3}}

[testenv]
description = run unit tests
deps =
    -rrequirements.txt
commands =
    pytest {posargs:tests}

[testenv:typeguard_{v2,v3}]
description = run tests with typeguard versions
base_python =
    py310: python3.10
deps =
    v2: typeguard<3.0.0
    v3: typeguard>=3.0.0
    -rrequirements.txt
commands =
    pytest {posargs:tests}

But it looks like it uses the latest typeguard version in all tests. The requirements.txt holds typeguard without a specific version.

How can this be configured to create two environments with different typeguard versions?


Solution

  • As @sinoroc pointed out, the problem is with env_list. To py{} and typeguard-{} should be separated. So should be the addressing to those environments based on the full environment name i.e. v2 and v3.

    [tox]
    requires =
        tox>=4
    env_list = py{37,38,39,310,311},typeguard-{v2,v3}
    
    [testenv]
    description = run unit tests
    deps =
        -rrequirements.txt
    commands =
        pytest {posargs:tests}
    
    [testenv:typeguard-{v2,v3}]
    description = run tests with typeguard versions
    base_python = py310
    deps =
        v2: typeguard<3.0.0
        v3: typeguard>=3.0.0
        -rrequirements.txt
    commands =
        pytest {posargs:tests}
    

    This is the corrected code