[tox]
envlist = py27,py26,py34,py33,py35,py36,pypy,style,py26-bare,docs
minversion = 2.7.0

[testenv]
description = run the unit tests with pytest under the current Python env
setenv = COVERAGE_FILE=.coverage.{envname}
passenv = CI TRAVIS TRAVIS_*
deps = pytest >= 3.0.0
       pytest-cov
       pytest-timeout
       pytest-xdist
;NOTE --cov-config={toxinidir}/tox.ini is necessary until
;https://github.com/pytest-dev/pytest-cov/issues/168 is fixed
commands = pytest {posargs:tests} --cov-config={toxinidir}/tox.ini --cov={envsitepackagesdir}/tox --timeout=180

[testenv:dev]
description = DEV environment, if no posarg is specified: run pytest
# required to make looponfail reload on every source code change
usedevelop = True
commands = {posargs:py.test -s -x -f -v}

[testenv:docs]
description = invoke sphinx-build and try to build the HTML page, and check that URIs are valid
basepython = python
deps = sphinx >= 1.6.3, < 2
       towncrier >= 17.8.0
       {[testenv]deps}
passenv = http_proxy https_proxy no_proxy SSL_CERT_FILE
commands = sphinx-build -d .tox/docs_doctree doc .tox/docs_out --color -W -bhtml
           sphinx-build -d .tox/docs_doctree doc .tox/docs_out --color -W -blinkcheck

[testenv:style]
basepython = python3.6
deps = flake8 == 3.4.1
       flake8-bugbear == 17.4.0
       pre-commit == 1.0.1
description = run static analysis and style check using flake8
commands = python -m flake8 --show-source tox setup.py {posargs}
           python -m flake8 --show-source doc tests {posargs}
           pre-commit run --all-files
[flake8]
max-complexity = 22
max-line-length = 99

[testenv:py26-bare]
description = invoke the tox help message under Python 2.6
install_command = pip install {opts} {packages}
list_dependencies_command = pip freeze
deps =
commands = tox -h

[testenv:py26]
install_command = pip install {opts} {packages}
list_dependencies_command = pip freeze

[testenv:X]
description = print the positional arguments passed in with echo
commands = echo {posargs}

[testenv:coverage]
description = [run locally after tests]: combine coverage data and create reports
skip_install = True
setenv = COVERAGE_FILE=.coverage
deps = coverage
commands = coverage erase
           coverage combine
           coverage xml
           coverage html

[testenv:codecov]
description = [only run on CI]: upload coverage data to codecov
;NOTE token should not be necesssary but seems to be on appveyor
setenv = {[testenv:coverage]setenv}
         CODECOV_TOKEN = 01eb408d-0640-4527-a5f6-9dfe30f9f2ba
deps = codecov
commands = codecov --required

[coverage:run]
branch = true
source = tox
omit = tox/__main__.py

[coverage:paths]
source = tox
         .tox/*/lib/python*/site-packages/tox
         .tox/pypy*/site-packages/tox

[coverage:report]
exclude_lines = if __name__ == ["']__main__["']:

[pytest]
addopts = -rsxX
rsyncdirs = tests tox
looponfailroots = tox tests
norecursedirs = .hg .tox
xfail_strict = True
