Add expected exceptions to 'DID NOT RAISE' msg
This commit is contained in:
parent
fde44f4f30
commit
79722ae89b
|
@ -49,6 +49,7 @@
|
||||||
``--failed-first`` respectively.
|
``--failed-first`` respectively.
|
||||||
Thanks `@MichaelAquilina`_ for the PR.
|
Thanks `@MichaelAquilina`_ for the PR.
|
||||||
|
|
||||||
|
* Added expected exceptions to pytest.raises fail message
|
||||||
|
|
||||||
**Bug Fixes**
|
**Bug Fixes**
|
||||||
|
|
||||||
|
|
|
@ -1311,7 +1311,7 @@ def raises(expected_exception, *args, **kwargs):
|
||||||
func(*args[1:], **kwargs)
|
func(*args[1:], **kwargs)
|
||||||
except expected_exception:
|
except expected_exception:
|
||||||
return _pytest._code.ExceptionInfo()
|
return _pytest._code.ExceptionInfo()
|
||||||
pytest.fail("DID NOT RAISE")
|
pytest.fail("DID NOT RAISE {0}".format(expected_exception))
|
||||||
|
|
||||||
class RaisesContext(object):
|
class RaisesContext(object):
|
||||||
def __init__(self, expected_exception):
|
def __init__(self, expected_exception):
|
||||||
|
@ -1770,7 +1770,6 @@ class FixtureLookupError(LookupError):
|
||||||
# the last fixture raise an error, let's present
|
# the last fixture raise an error, let's present
|
||||||
# it at the requesting side
|
# it at the requesting side
|
||||||
stack = stack[:-1]
|
stack = stack[:-1]
|
||||||
|
|
||||||
for function in stack:
|
for function in stack:
|
||||||
fspath, lineno = getfslineno(function)
|
fspath, lineno = getfslineno(function)
|
||||||
try:
|
try:
|
||||||
|
|
|
@ -70,3 +70,9 @@ class TestRaises:
|
||||||
def test_tuple(self):
|
def test_tuple(self):
|
||||||
with pytest.raises((KeyError, ValueError)):
|
with pytest.raises((KeyError, ValueError)):
|
||||||
raise KeyError('oops')
|
raise KeyError('oops')
|
||||||
|
|
||||||
|
def test_no_raise_message(self):
|
||||||
|
try:
|
||||||
|
pytest.raises(ValueError, int, '0')
|
||||||
|
except pytest.raises.Exception as e:
|
||||||
|
assert e.msg == "DID NOT RAISE {0}".format(repr(ValueError))
|
||||||
|
|
Loading…
Reference in New Issue