Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to clean a tox environment after running?

Tags:

python

tox

I have the following tox.ini file:

[tox]
envlist = flake8,py{35,36,37,38}{,-keyring}

[testenv]
usedevelop = True
install_command = pip install -U {opts} {packages}
deps =
    .[test]
    keyring: .[keyring]
setenv =
    COVERAGE_FILE = .coverage.{envname}
commands=
    pytest {toxinidir}/tests -n 4 {posargs}

[testenv:flake8]
basepython = python3
deps = flake8
commands=
    flake8 src tests

[flake8]
ignore: F401,E402,E501,W605,W503

When I run the tox command, it creates a .tox folder containing a folder for every environment specified in the [tox] section of the tox.ini.

I would like to get read automatically of these particular folders after the test have succeeded when running tox without having to manually run rm -rf .tox/NAME_OF_THE_ENV. I have searched through the tox documentation but I have found nothing.

Is it possible to do so? If yes, how?

like image 529
vinzee Avatar asked Jan 02 '20 12:01

vinzee


People also ask

What is tox Envlist?

[tox]envlist is only a default — a list of environments to run when tox is invoked without option -e and without TOXENV environment variable. Once you use tox -e [tox]envlist is ignored. You can run local environment with different python versions, but I don't know any way to run it multiple times.

What does tox do?

What is tox? Tox is a tool that creates virtual environments, and installs the configured dependencies for those environments, for the purpose of testing a Python package (i.e. something that will be shared via PyPi, and so it only works with code that defines a setup.py ).


2 Answers

I know it's not exactly what you were asking for but it's worth mentioning that the -r / --recreate flag to tox will force recreation of virtual environments

like image 131
Matthew Hegarty Avatar answered Sep 17 '22 12:09

Matthew Hegarty


There is no way in tox. The reason is that tox preserves these environments as a cache: next time you run tox the environments will be reused thus saving time.

You can remove them at once after running tox with rm -rf .tox.

like image 31
phd Avatar answered Sep 17 '22 12:09

phd