DEV Community

Cover image for Using Python3's ‘venv’ with tox
Jürgen Hermann
Jürgen Hermann

Posted on • Updated on • Originally published at jhermann.github.io

Using Python3's ‘venv’ with tox

Using the built-in Python module in favor of virtualenv to create your testing or project automation environments.

tox is a generic virtualenv management and test command line tool, especially useful for multi-environment testing. It has a plugin architecture, with plenty of both built-in and 3rd party extensions.

This post assumes you are already familiar with tox and have a working configuration for it. If not, check out its documentation.

In order to make tox use the built-in virtual environment venv of Python 3.3+, there is a plugin named tox-venv that switches from using virtualenv to venv whenever it is available.

GitHub logo tox-dev / tox-venv

Use Python 3 venvs for Python 3 test environments

Typically, venv is more robust when faced with ever-changing runtime environments and versions of related tooling (pip, setuptools, …).

To enable that plugin, add this to your tox.ini:

[tox]
requires = tox-venv

That merely triggers tox to check (on startup) that the plugin is installed. You still have to add it to your dev-requirements.txt or a similar file, so it gets installed together with tox. You can also install tox globally using dephell jail install tox tox-venv – see the first post in this series for details.

The end result is this (call tox -v to see those messages):

py38 create: …/.tox/py38
  …/.tox$ /usr/bin/python3.8 -m venv py38 >…/log/py38-0.log

And there you have it, no more virtualenv package needed. 🎉 🎊

Top comments (0)