Re-enable docstring testing of _pytest modules on CI
* Fix doctests * List one env per line in tox.ini * "doctesting" tox env now also tests docstrings using doctest
This commit is contained in:
parent
c0719a5b4c
commit
37dcdfbc58
|
@ -1105,7 +1105,9 @@ def raises(expected_exception, *args, **kwargs):
|
||||||
|
|
||||||
>>> with raises(ZeroDivisionError, message="Expecting ZeroDivisionError"):
|
>>> with raises(ZeroDivisionError, message="Expecting ZeroDivisionError"):
|
||||||
... pass
|
... pass
|
||||||
... Failed: Expecting ZeroDivisionError
|
Traceback (most recent call last):
|
||||||
|
...
|
||||||
|
Failed: Expecting ZeroDivisionError
|
||||||
|
|
||||||
|
|
||||||
.. note::
|
.. note::
|
||||||
|
@ -1116,19 +1118,21 @@ def raises(expected_exception, *args, **kwargs):
|
||||||
Lines of code after that, within the scope of the context manager will
|
Lines of code after that, within the scope of the context manager will
|
||||||
not be executed. For example::
|
not be executed. For example::
|
||||||
|
|
||||||
>>> with raises(OSError) as exc_info:
|
>>> value = 15
|
||||||
assert 1 == 1 # this will execute as expected
|
>>> with raises(ValueError) as exc_info:
|
||||||
raise OSError(errno.EEXISTS, 'directory exists')
|
... if value > 10:
|
||||||
assert exc_info.value.errno == errno.EEXISTS # this will not execute
|
... raise ValueError("value must be <= 10")
|
||||||
|
... assert str(exc_info.value) == "value must be <= 10" # this will not execute
|
||||||
|
|
||||||
Instead, the following approach must be taken (note the difference in
|
Instead, the following approach must be taken (note the difference in
|
||||||
scope)::
|
scope)::
|
||||||
|
|
||||||
>>> with raises(OSError) as exc_info:
|
>>> with raises(ValueError) as exc_info:
|
||||||
assert 1 == 1 # this will execute as expected
|
... if value > 10:
|
||||||
raise OSError(errno.EEXISTS, 'directory exists')
|
... raise ValueError("value must be <= 10")
|
||||||
|
...
|
||||||
|
>>> assert str(exc_info.value) == "value must be <= 10"
|
||||||
|
|
||||||
assert exc_info.value.errno == errno.EEXISTS # this will now execute
|
|
||||||
|
|
||||||
Or you can specify a callable by passing a to-be-called lambda::
|
Or you can specify a callable by passing a to-be-called lambda::
|
||||||
|
|
||||||
|
|
|
@ -36,8 +36,13 @@ def deprecated_call(func=None, *args, **kwargs):
|
||||||
|
|
||||||
This function can be used as a context manager::
|
This function can be used as a context manager::
|
||||||
|
|
||||||
|
>>> import warnings
|
||||||
|
>>> def api_call_v2():
|
||||||
|
... warnings.warn('use v3 of this api', DeprecationWarning)
|
||||||
|
... return 200
|
||||||
|
|
||||||
>>> with deprecated_call():
|
>>> with deprecated_call():
|
||||||
... myobject.deprecated_method()
|
... assert api_call_v2() == 200
|
||||||
|
|
||||||
Note: we cannot use WarningsRecorder here because it is still subject
|
Note: we cannot use WarningsRecorder here because it is still subject
|
||||||
to the mechanism that prevents warnings of the same type from being
|
to the mechanism that prevents warnings of the same type from being
|
||||||
|
|
|
@ -20,10 +20,11 @@ install:
|
||||||
# install pypy using choco (redirect to a file and write to console in case
|
# install pypy using choco (redirect to a file and write to console in case
|
||||||
# choco install returns non-zero, because choco install python.pypy is too
|
# choco install returns non-zero, because choco install python.pypy is too
|
||||||
# noisy)
|
# noisy)
|
||||||
- choco install python.pypy > pypy-inst.log 2>&1 || (type pypy-inst.log & exit /b 1)
|
# pypy is disabled until #1963 gets fixed
|
||||||
- set PATH=C:\tools\pypy\pypy;%PATH% # so tox can find pypy
|
#- choco install python.pypy > pypy-inst.log 2>&1 || (type pypy-inst.log & exit /b 1)
|
||||||
- echo PyPy installed
|
#- set PATH=C:\tools\pypy\pypy;%PATH% # so tox can find pypy
|
||||||
- pypy --version
|
#- echo PyPy installed
|
||||||
|
#- pypy --version
|
||||||
|
|
||||||
- C:\Python35\python -m pip install tox
|
- C:\Python35\python -m pip install tox
|
||||||
|
|
||||||
|
|
28
tox.ini
28
tox.ini
|
@ -3,9 +3,18 @@ minversion=2.0
|
||||||
distshare={homedir}/.tox/distshare
|
distshare={homedir}/.tox/distshare
|
||||||
# make sure to update enviroment list on appveyor.yml
|
# make sure to update enviroment list on appveyor.yml
|
||||||
envlist=
|
envlist=
|
||||||
linting,py26,py27,py33,py34,py35,pypy,
|
linting
|
||||||
{py27,py35}-{pexpect,xdist,trial},
|
py26
|
||||||
py27-nobyte,doctesting,freeze,docs
|
py27
|
||||||
|
py33
|
||||||
|
py34
|
||||||
|
py35
|
||||||
|
pypy
|
||||||
|
{py27,py35}-{pexpect,xdist,trial}
|
||||||
|
py27-nobyte
|
||||||
|
doctesting
|
||||||
|
freeze
|
||||||
|
docs
|
||||||
|
|
||||||
[testenv]
|
[testenv]
|
||||||
commands= pytest --lsof -rfsxX {posargs:testing}
|
commands= pytest --lsof -rfsxX {posargs:testing}
|
||||||
|
@ -90,10 +99,6 @@ deps={[testenv:py27-trial]deps}
|
||||||
commands=
|
commands=
|
||||||
pytest -ra {posargs:testing/test_unittest.py}
|
pytest -ra {posargs:testing/test_unittest.py}
|
||||||
|
|
||||||
[testenv:doctest]
|
|
||||||
commands=pytest --doctest-modules _pytest
|
|
||||||
deps=
|
|
||||||
|
|
||||||
[testenv:docs]
|
[testenv:docs]
|
||||||
basepython=python
|
basepython=python
|
||||||
changedir=doc/en
|
changedir=doc/en
|
||||||
|
@ -106,9 +111,12 @@ commands=
|
||||||
|
|
||||||
[testenv:doctesting]
|
[testenv:doctesting]
|
||||||
basepython = python
|
basepython = python
|
||||||
changedir=doc/en
|
usedevelop=True
|
||||||
|
skipsdist=True
|
||||||
deps=PyYAML
|
deps=PyYAML
|
||||||
commands= pytest -rfsxX {posargs}
|
commands=
|
||||||
|
pytest -rfsxX doc/en
|
||||||
|
pytest --doctest-modules {toxinidir}/_pytest
|
||||||
|
|
||||||
[testenv:regen]
|
[testenv:regen]
|
||||||
changedir=doc/en
|
changedir=doc/en
|
||||||
|
@ -139,7 +147,7 @@ commands=
|
||||||
[testenv:coveralls]
|
[testenv:coveralls]
|
||||||
passenv = TRAVIS TRAVIS_JOB_ID TRAVIS_BRANCH COVERALLS_REPO_TOKEN
|
passenv = TRAVIS TRAVIS_JOB_ID TRAVIS_BRANCH COVERALLS_REPO_TOKEN
|
||||||
usedevelop=True
|
usedevelop=True
|
||||||
basepython=python3.4
|
basepython=python3.5
|
||||||
changedir=.
|
changedir=.
|
||||||
deps =
|
deps =
|
||||||
{[testenv]deps}
|
{[testenv]deps}
|
||||||
|
|
Loading…
Reference in New Issue