diff --git a/py/_test/outcome.py b/py/_test/outcome.py index 619de1309..f58f396c1 100644 --- a/py/_test/outcome.py +++ b/py/_test/outcome.py @@ -100,7 +100,7 @@ def raises(ExpectedException, *args, **kwargs): k = ", ".join(["%s=%r" % x for x in kwargs.items()]) if k: k = ', ' + k - expr = '%s(%r%s)' %(func.__name__, args, k) + expr = '%s(%r%s)' %(getattr(func, '__name__', func), args, k) raise ExceptionFailure(msg="DID NOT RAISE", expr=args, expected=ExpectedException) diff --git a/testing/test_outcome.py b/testing/test_outcome.py index f415d13c0..a7a782aba 100644 --- a/testing/test_outcome.py +++ b/testing/test_outcome.py @@ -15,6 +15,16 @@ class TestRaises: def test_raises_function(self): py.test.raises(ValueError, int, 'hello') + def test_raises_callable_no_exception(self): + from py._test.outcome import ExceptionFailure + class A: + def __call__(self): + pass + try: + py.test.raises(ValueError, A()) + except ExceptionFailure: + pass + def test_pytest_exit(): try: py.test.exit("hello")