function: test.raises

 raise AssertionError, if target code does not raise the expected
        exception.
    
def raises(ExpectedException, *args, **kwargs):

origin:<UNKNOWN>

where:

exceptions that might appear during execution:

function source:

def raises(ExpectedException, *args, **kwargs):
    """ raise AssertionError, if target code does not raise the expected
        exception.
    """
    assert args
    __tracebackhide__ = True 
    if isinstance(args[0], str):
        expr, = args
        assert isinstance(expr, str)
        frame = sys._getframe(1)
        loc = frame.f_locals.copy()
        loc.update(kwargs)
        #print "raises frame scope: %r" % frame.f_locals
        source = py.code.Source(expr)
        try:
            exec source.compile() in frame.f_globals, loc
            #del __traceback__
            # XXX didn'T mean f_globals == f_locals something special?
            #     this is destroyed here ...
        except ExpectedException:
            return py.code.ExceptionInfo()
    else:
        func = args[0]
        assert callable
        try:
            func(*args[1:], **kwargs)
            #del __traceback__
        except ExpectedException:
            return py.code.ExceptionInfo()
        k = ", ".join(["%s=%r" % x for x in kwargs.items()])
        if k:
            k = ', ' + k
        expr = '%s(%r%s)' %(func.__name__, args, k)
    raise ExceptionFailure(msg="DID NOT RAISE", 
                           expr=args, expected=ExpectedException) 

call sites:

called in /home/johnny/projects/merlinux/py/dist/py/code/testing/test_excinfo.py

traceback test.raises.0

called in /home/johnny/projects/merlinux/py/dist/py/code/testing/test_source.py

traceback test.raises.1

called in /home/johnny/projects/merlinux/py/dist/py/c-extension/greenlet/test_throw.py

traceback test.raises.2

called in /home/johnny/projects/merlinux/py/dist/py/builtin/testing/test_reversed.py

traceback test.raises.3

called in /home/johnny/projects/merlinux/py/dist/py/apigen/source/testing/test_browser.py

traceback test.raises.4

called in /home/johnny/projects/merlinux/py/dist/py/c-extension/greenlet/test_greenlet.py

traceback test.raises.5

called in /home/johnny/projects/merlinux/py/dist/py/code/testing/test_code.py

traceback test.raises.6

called in /home/johnny/projects/merlinux/py/dist/py/code/testing/test_source.py

traceback test.raises.7

called in /home/johnny/projects/merlinux/py/dist/py/code/testing/test_excinfo.py

traceback test.raises.8

called in /home/johnny/projects/merlinux/py/dist/py/apigen/source/testing/test_browser.py

traceback test.raises.9

called in /home/johnny/projects/merlinux/py/dist/py/code/testing/test_source.py

traceback test.raises.10

called in /home/johnny/projects/merlinux/py/dist/py/c-extension/greenlet/test_greenlet.py

traceback test.raises.11

called in /home/johnny/projects/merlinux/py/dist/py/code/testing/test_excinfo.py

traceback test.raises.12

called in /home/johnny/projects/merlinux/py/dist/py/code/testing/test_excinfo.py

traceback test.raises.13

called in /home/johnny/projects/merlinux/py/dist/py/code/testing/test_source.py

traceback test.raises.14

called in /home/johnny/projects/merlinux/py/dist/py/documentation/example/pytest/failure_demo.py

traceback test.raises.15

called in /home/johnny/projects/merlinux/py/dist/py/documentation/example/pytest/failure_demo.py

traceback test.raises.16

called in /home/johnny/projects/merlinux/py/dist/py/code/testing/test_excinfo.py

traceback test.raises.17

called in /home/johnny/projects/merlinux/py/dist/py/execnet/testing/test_gateway.py

traceback test.raises.18

called in /home/johnny/projects/merlinux/py/dist/py/builtin/testing/test_reversed.py

traceback test.raises.19

called in /home/johnny/projects/merlinux/py/dist/py/code/testing/test_excinfo.py

traceback test.raises.20