question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

How to run tox and poetry together against multiple dependency versions

See original GitHub issue
  • I have searched the issues of this repo and believe that this is not a duplicate.
  • I have searched the documentation and believe that my question is not covered.

Issue

I have a question around the use of poetry and tox, when testing a library against a matrix of supported dependencies. My current example is a Django app, which I would like to test against Django 2.2. and 3.0. The tox.ini config is as below (taken from the docs - https://python-poetry.org/docs/faq/#is-tox-supported):

[tox]
envlist = py{36,37,38}-django{22,30}

[testenv]
deps =
    django22: Django==2.2
    django30: Django==3.0

whitelist_externals = poetry
skip_install = true

commands =
    poetry install -vvv
    poetry run django-admin --version
    poetry run pytest tests/

My pyproject.toml file lists the Django dependency as:

[tool.poetry.dependencies]
python = "^3.6"
django = "^2.2 || ^3.0"

When running tox, the version number output for all test runs is 3.0. It looks like the lock file is created on the first test run, and then re-used for the rest, and that the lock file is always the latest version of Django (3.0), even when 2.2 is already installed.

I’m a bit stuck at this point, as without being able to test against a matrix of versions I can’t progress. Any help gratefully received. (I am also happy to add a docs PR once I’ve worked out the solution, as I can’t be the only person with this issue?)


Update: adding output from a test run that shows a.) Django 2.2 being installed by tox, and then b.) poetry overwriting it.

my-app$ tox -r -e py36-django22
py36-django22 recreate: .tox/py36-django22
py36-django22 installdeps: Django==2.2
py36-django22 installed: Django==2.2,my-app==0.1.0,pytz==2019.3,sqlparse==0.3.0
py36-django22 run-test: commands[0] | poetry install -vvv
Using virtualenv: .tox/py36-django22
Updating dependencies
Resolving dependencies...
   1: derived: django (^2.2 || ^3.0)
   ...
PyPI: 10 packages found for django >=2.2,<4.0
   ...
   1: Version solving took 3.330 seconds.
   1: Tried 1 solutions.

Writing lock file

Package operations: 52 installs, 1 update, 0 removals, 3 skipped

  - ...
  - Updating django (2.2 -> 3.0)
  - ...

Issue Analytics

  • State:closed
  • Created 4 years ago
  • Reactions:8
  • Comments:14 (1 by maintainers)

github_iconTop GitHub Comments

6reactions
sinoroccommented, Oct 21, 2020

I think a good course of action, would be for people here (i.e. people who have experience with tox and poetry), to make some clear condensed suggestion of what they would like to see in the documentation/FAQ.

  • keep it short
  • keep it non opinionated
  • keep it general enough that anyone can use it without being surprising / counter-intuitive
  • keep it simple for beginners
  • make it meaningful so that it is clear what task the poetry+tox combination achieves (test against multiple Python versions and/or test against multiple versions of a dependency)
  • avoid suggesting 3rd party tool (I do not think tox plugins should be in the FAQ)

Someone already made a pull request: https://github.com/python-poetry/poetry/pull/2416

Maybe people should go have a look at it, comment on it, make suggestions, etc.

6reactions
sinoroccommented, Sep 11, 2020

I published on PyPI a plugin for Tox to instruct it to install Poetry’s development dependencies in the test environments: tox-poetry-dev-dependencies. It’s just a proof of concept. I didn’t test much, only with a very simple project.

Read more comments on GitHub >

github_iconTop Results From Across the Web

How can I get tox and poetry to work together to support ...
So - my question is - how do I set up a multi-version tox (or travis) test matrix, with poetry as the dependency...
Read more >
Python: A toxic work environment (tox & poetry)
Using tox with poetry makes managing dependencies easy, especially if you have the need to work on multiple different Python projects. Creating ...
Read more >
Tox with Pyenv & Poetry to Test Projects with Multiple Python ...
This post will cover what this research found and how to get tox to use pyenv and poetry to test a project against...
Read more >
FAQ | Documentation | Poetry - Python dependency ...
tox can be configured in multiple ways. It depends on what should be the code under test and which dependencies should be installed....
Read more >
tox-poetry - PyPI
Plugin installs all dependencies from pyproject.toml before running any commands. Like simple tox deps , poetry dependencies are installed only once when ...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found