Ghost
Ghost

Reputation: 11

Tox running test against already activated virtualenv instead of creating isolated virtualenv with envlist and running test in it

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

Upvotes: 1

Views: 693

Answers (1)

Jürgen Gmach
Jürgen Gmach

Reputation: 6121

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

Upvotes: 1

Related Questions