DEV Community

loading...
Cover image for Using Python3's ‘venv’ with tox

Using Python3's ‘venv’ with tox

Jürgen Hermann
A long long time ago, I started with Python 1.5 at web.de, founded the MoinMoin wiki project shortly thereafter, and am now enjoying the increased traction that Python recently gets from data science.
Originally published at jhermann.github.io Updated on ・1 min read

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. 🎉 🎊

Discussion (0)