0

I'm struggling with tox tool. I have tox installed in my activated virtual environment, lets call the virtual environment parentenv. I basically use tox to test my project against different versions of Python. Based on my understanding of tox, it's supposed create isolated virtual environments, install all dependencies and run test in those isolated virtual environments. The error I'm facing is that tox is able to created these virtual environments but fails to activate these isolated virtual environments and rather uses the virtual environment of the project (i.e.: parentenv) and run the tests in that environment.

Below is the content of my tox.ini located in the project's root directory. All commands are run from the root directory.

tox.ini

[tox]
envlist = py39, py310
skipsdist = true

[testenv]
allowlist_externals = poetry
commands =
    poetry install -v
    poetry run pytest here

My Workflow is (commands are run from the project's root directory):

$ poetry shell
$ tox

Below is a sample output from running tox:

sample output

sinoroc
  • 18,409
  • 2
  • 39
  • 70
Ghost
  • 1
  • Isn't the issue that Poetry always handles the virtual environment on its own (in other words, it ignores that a virtual environment is already active, the *tox* one)? -- Maybe related: https://stackoverflow.com/q/59377071 – sinoroc Feb 13 '23 at 14:58

1 Answers1

1

Having a look at your "sample output", the second marked line is not from tox, but from poetry.

You should have a look at the official documentation of poetry for tox: https://python-poetry.org/docs/faq/#is-tox-supported

The differences at first sight:

  • you need to configure the build backend (unclear whether you did it as you did not show us your pyproject.toml)
  • you need to use the isolated_build directive in your tox.ini
Jürgen Gmach
  • 5,366
  • 3
  • 20
  • 37
  • I have configured the backend build. This is a snippet from my pyproject.toml [build-system] requires = ["poetry-core>=1.0.0"] build-backend = "poetry.core.masonry.api". I have also tried the tox.ini settings from the link you share but yet still the error persist – Ghost Feb 13 '23 at 14:29
  • 1
    `isolated_build` is the default on tox v4+, isn't it? – sinoroc Feb 13 '23 at 14:57