How can I get tox and poetry to work together to support testing multiple versions of a Python dependency?

前端 未结 1 931
不思量自难忘°
不思量自难忘° 2021-02-07 08:52

I am switching a project that currently uses pipenv to poetry as a test to see what the differences are. The project is a simple, redistributable, Djan

相关标签:
1条回答
  • 2021-02-07 09:28

    Haven't thoroughly tested it, but I believe something like this should work:

    [tox]
    envlist = py{36,37,38}-django{22,30}
    isolated_build = True
    
    [testenv]
    deps =
        django22: Django==2.2
        django30: Django==3.0
        # plus the dev dependencies
        pytest
        coverage
    
    commands =
        pytest --cov=my_app tests/
        coverage report -m
    

    See the "poetry" section in the "packaging" chapter of the tox documentation.


    In order to avoid the repetition of the dev dependencies, one could try the following variation based on the extras feature:

    tox.ini

    [tox]
    # ...
    
    [testenv]
    # ...
    deps =
        django22: Django==2.2
        django30: Django==3.0
    extras =
        test
    

    pyproject.toml

    [tool.poetry]
    # ...
    
    [tool.poetry.dependencies]
    python = "^3.6"
    django = "^2.2 || ^3.0"
    #
    pytest = { version = "^5.2", optional = true }
    
    [tool.poetry.extras]
    test = ["pytest"]
    
    [build-system]
    # ...
    

    Nowadays there are tox plug-ins that try to make for a better integration with poetry-based projects:

    • tox-poetry-installer
    • tox-poetry-dev-dependencies (disclaimer: my project)
    • tox-poetry
    0 讨论(0)
提交回复
热议问题