summaryrefslogtreecommitdiff
path: root/testing
diff options
context:
space:
mode:
authorKirill Pinchuk <cybergrind@gmail.com>2017-08-21 17:28:29 +0300
committerKirill Pinchuk <cybergrind@gmail.com>2017-08-23 17:17:03 +0300
commit12b1bff6c5cf167662870ea212fa6d8061d48e94 (patch)
tree5dd3ba14172ae3a9fa9a81a6967f469a2c5c550a /testing
parent539523cfee4c49a765569abcf68134b1255eedb5 (diff)
downloadpytest-12b1bff6c5cf167662870ea212fa6d8061d48e94.tar.gz
`compat.safe_getattr` now catches OutcomeExceptions too
Diffstat (limited to 'testing')
-rw-r--r--testing/test_compat.py27
1 files changed, 26 insertions, 1 deletions
diff --git a/testing/test_compat.py b/testing/test_compat.py
index 7b2251ef6..c74801c6c 100644
--- a/testing/test_compat.py
+++ b/testing/test_compat.py
@@ -2,7 +2,8 @@ from __future__ import absolute_import, division, print_function
import sys
import pytest
-from _pytest.compat import is_generator, get_real_func
+from _pytest.compat import is_generator, get_real_func, safe_getattr
+from _pytest.outcomes import OutcomeException
def test_is_generator():
@@ -74,3 +75,27 @@ def test_is_generator_async_syntax(testdir):
""")
result = testdir.runpytest()
result.stdout.fnmatch_lines(['*1 passed*'])
+
+
+class ErrorsHelper(object):
+ @property
+ def raise_exception(self):
+ raise Exception('exception should be catched')
+
+ @property
+ def raise_fail(self):
+ pytest.fail('fail should be catched')
+
+
+def test_helper_failures():
+ helper = ErrorsHelper()
+ with pytest.raises(Exception):
+ helper.raise_exception
+ with pytest.raises(OutcomeException):
+ helper.raise_fail
+
+
+def test_safe_getattr():
+ helper = ErrorsHelper()
+ assert safe_getattr(helper, 'raise_exception', 'default') == 'default'
+ assert safe_getattr(helper, 'raise_fail', 'default') == 'default'