Since I introduced tox after studying with CI for Python module, I will describe the contents that I often write in the configuration file for myself.
> = 3.14
.It is a tool that can perform tests in MultiEnvironment using virtualenv
.
It's nice to be able to test modules with multiple versions of Python.
According to the document, three types of files are read in the following order of priority.
The contents of tox.ini
are described below.
A list of embedded variables available in each section.
Setting name | Overview |
---|---|
{toxinidir} | tox.ini Directory where |
{toxworkdir} | Directory where the virtual environment is created |
{envname} | Virtual environment name,[tox:{envname}] What was described in the part of |
{envdir} | Virtual environment directory, by default{toxworkdir}/{envname} |
This section describes common settings. [tox]
Described below.
Setting name | Overview | Default value |
---|---|---|
envlist | Multiple execution environments can be described by enumerating, separating with commas, or line breaks. Basically described py37``py38 Some are prepared by default |
- |
toxworkdir | Directory where the virtual environment is created Files created by tox are stored in this directory |
{toxinidir}/.tox |
skipsdist | Whether to package the resultstrue Skip with |
false |
skip_missing_interpreters | Set the return code when it fails in the interpreter relationshiptrue If it fails, return the code that is considered successful,config Reads from the config file |
config |
example
tox.ini
[tox]
envlist =
py38, py37
flake8
isort
skipsdist = true
skip_missing_interpreters = true
This section describes the details of each environment described in the envlist of the global section. [tox: {envname}]
Described below.
Setting name | Overview | Default value |
---|---|---|
commands | Mandatory Command content to be executed in the current environment coverage run -p -m pytest Orflake8 Set etc. |
- |
deps | Specify the dependencies required to execute the command Specify the module directly or require.Describe in txt -rrequirements.txt Specify withIn short pip install Optional part of |
- |
passenv | Specify the environment variable that you want to inherit to the execution virtual environmentLANG``PIP_INDEX_URL Etc. can be set |
- |
setenv | Set new environment variables in the execution virtual environment | - |
whitelist_externals | It is not prepared on the execution virtual environment side, but specify it when you want to use it without problems with commands in the local environment. | - |
alwayscopy | If you don't like symbolic links to Python filestrue Designation |
false |
changedir | Specify the working directory when executing the command | {toxinidir} |
envlogdir | Set log file storage | {envdir}/log |
description | Give a brief description The contents are displayed if verbose is specified when executing the environment display command with tox. |
no description |
example
tox.ini
[tox]
envlist =
py38
flake8
skipsdist = true
#Details of py38 environment
[testenv]
passenv = LANG
deps = -rrequirements.txt
passenv = PYTHONPATH
setenv =
PYTHONDONTWRITEBYTECODE=1
changedir = tests
commands =
coverage run -p -m pytest
#details of flake8 environment
[testenv:flake8]
skip_install = true
deps =
flake8 >= 3.7
flake8-import-order
changedir = {toxinidir}
description = 'check pep8 style'
commands = flake8 module
The settings for pytest and flake8 itself are described in setup.cfg
.
setup.cfg
[tool:pytest]
testpaths = tests
[coverage:run]
branch = True
source =
module
tests
[flake8]
exclude = build,.git/*,.tox/*,./tests/*
ignore =
# allow Multiple spaces before Operator
E221
max-line-length = 140
Reference -Official Document
Recommended Posts