我有以下tox.ini
文件:
[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
当我运行tox
命令时,它将创建一个.tox
文件夹,其中包含针对的[tox]
部分中指定的每个环境的文件夹tox.ini
。
我想在测试成功运行后自动读取这些特定的文件夹,tox
而无需手动运行rm -rf .tox/NAME_OF_THE_ENV
。我搜索了毒物文档,但没有发现任何东西。
有可能这样做吗?如果是,怎么办?
我找到了一种创建毒钩的方法。在环境中运行shutil.rmtree
测试之后,此挂钩将运行命令。
在tox_clean_env.py
文件中:
import shutil
from tox import hookimpl
@hookimpl
def tox_runtest_post(venv):
try:
shutil.rmtree(venv.path)
except Exception as e:
print("An exception occurred while removing '{}':".format(venv.path))
print(e)
我围绕此代码创建了一个程序包,只需要使用进行安装pip
。
在我setup.py
的setup
函数中:
entry_points={"tox": ["clean_env = tox_clean_env"]},
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句