summaryrefslogtreecommitdiff
path: root/_pytest
diff options
context:
space:
mode:
authorBruno Oliveira <nicoddemus@gmail.com>2016-11-08 21:34:45 -0200
committerBruno Oliveira <nicoddemus@gmail.com>2016-11-08 22:20:27 -0200
commit1130b9f742d053a429149e56b8a0c8aec72a9968 (patch)
treedb4245baa65837fee4ceba8d082cabdd814b3f27 /_pytest
parent552c7d4286f582255752730d2c512d0aff4a44c4 (diff)
downloadpytest-1130b9f742d053a429149e56b8a0c8aec72a9968.tar.gz
Fix the stubborn test about cyclic references left by pytest.raises
In Python 2, a context manager's __exit__() leaves sys.exc_info with the exception values even when it was supposed to suppress the exception, so we explicitly call sys.exc_clear() which removes the traceback and allow the object to be released. Also updated the test to not depend on the immediate destruction of the object but instead to ensure it is not being tracked as a cyclic reference. Fix #1965
Diffstat (limited to '_pytest')
-rw-r--r--_pytest/python.py6
1 files changed, 5 insertions, 1 deletions
diff --git a/_pytest/python.py b/_pytest/python.py
index a42e7185e..18432c1e7 100644
--- a/_pytest/python.py
+++ b/_pytest/python.py
@@ -1237,7 +1237,11 @@ class RaisesContext(object):
exc_type, value, traceback = tp
tp = exc_type, exc_type(value), traceback
self.excinfo.__init__(tp)
- return issubclass(self.excinfo.type, self.expected_exception)
+ suppress_exception = issubclass(self.excinfo.type, self.expected_exception)
+ if sys.version_info[0] == 2 and suppress_exception:
+ sys.exc_clear()
+ return suppress_exception
+
# builtin pytest.approx helper