diff --git a/_pytest/python.py b/_pytest/python.py index b04297b95..311ed6ec7 100644 --- a/_pytest/python.py +++ b/_pytest/python.py @@ -1194,6 +1194,25 @@ def raises(expected_exception, *args, **kwargs): >>> with raises(ZeroDivisionError): ... 1/0 + Or you can specify a callable by passing a to-be-called lambda:: + + >>> raises(ZeroDivisionError, lambda: 1/0) + + + or you can specify an arbitrary callable with arguments:: + + >>> def f(x): return 1/x + ... + >>> raises(ZeroDivisionError, f, 0) + + >>> raises(ZeroDivisionError, f, x=0) + + + A third possibility is to use a string to be executed:: + + >>> raises(ZeroDivisionError, "f(0)") + + .. note:: When using ``pytest.raises`` as a context manager, it's worthwhile to @@ -1216,25 +1235,6 @@ def raises(expected_exception, *args, **kwargs): assert err.errno = errno.EEXISTS # this will now execute - Or you can specify a callable by passing a to-be-called lambda:: - - >>> raises(ZeroDivisionError, lambda: 1/0) - - - or you can specify an arbitrary callable with arguments:: - - >>> def f(x): return 1/x - ... - >>> raises(ZeroDivisionError, f, 0) - - >>> raises(ZeroDivisionError, f, x=0) - - - A third possibility is to use a string to be executed:: - - >>> raises(ZeroDivisionError, "f(0)") - - Performance note: -----------------