diff options
author | Ronny Pfannschmidt <opensource@ronnypfannschmidt.de> | 2016-10-24 12:19:05 +0200 |
---|---|---|
committer | GitHub <noreply@github.com> | 2016-10-24 12:19:05 +0200 |
commit | 4e9c633185e3537f108d3229b39bb92528075a11 (patch) | |
tree | af9595f4f3d24ad554d4a5485abe7315bbd01604 /_pytest | |
parent | 7f95ea31d581bde8a3486e1794eff820d5b7c739 (diff) | |
parent | 37dcdfbc58441a266272d8ab4a8cc985ca51fb84 (diff) | |
download | pytest-4e9c633185e3537f108d3229b39bb92528075a11.tar.gz |
Merge pull request #2021 from nicoddemus/doctest-modules-ci
Re-enable docstring testing of _pytest modules on CI
Diffstat (limited to '_pytest')
-rw-r--r-- | _pytest/python.py | 22 | ||||
-rw-r--r-- | _pytest/recwarn.py | 7 |
2 files changed, 19 insertions, 10 deletions
diff --git a/_pytest/python.py b/_pytest/python.py index 62d2896ea..a42e7185e 100644 --- a/_pytest/python.py +++ b/_pytest/python.py @@ -1105,7 +1105,9 @@ def raises(expected_exception, *args, **kwargs): >>> with raises(ZeroDivisionError, message="Expecting ZeroDivisionError"): ... pass - ... Failed: Expecting ZeroDivisionError + Traceback (most recent call last): + ... + Failed: Expecting ZeroDivisionError .. note:: @@ -1116,19 +1118,21 @@ def raises(expected_exception, *args, **kwargs): Lines of code after that, within the scope of the context manager will not be executed. For example:: - >>> with raises(OSError) as exc_info: - assert 1 == 1 # this will execute as expected - raise OSError(errno.EEXISTS, 'directory exists') - assert exc_info.value.errno == errno.EEXISTS # this will not execute + >>> value = 15 + >>> with raises(ValueError) as exc_info: + ... if value > 10: + ... 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 scope):: - >>> with raises(OSError) as exc_info: - assert 1 == 1 # this will execute as expected - raise OSError(errno.EEXISTS, 'directory exists') + >>> with raises(ValueError) as exc_info: + ... if value > 10: + ... 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:: diff --git a/_pytest/recwarn.py b/_pytest/recwarn.py index a89474c03..87823bfbc 100644 --- a/_pytest/recwarn.py +++ b/_pytest/recwarn.py @@ -36,8 +36,13 @@ def deprecated_call(func=None, *args, **kwargs): 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(): - ... myobject.deprecated_method() + ... assert api_call_v2() == 200 Note: we cannot use WarningsRecorder here because it is still subject to the mechanism that prevents warnings of the same type from being |