summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMichael Seifert <michaelseifert04@yahoo.de>2016-10-18 00:56:44 +0200
committerBruno Oliveira <nicoddemus@gmail.com>2016-11-08 22:12:23 -0200
commit1e5b21cd6180009939130f6169c936427d0d4572 (patch)
tree27c55284f94345dc0aca068f960d63d72333e7f3
parent0b94c43baccf02268eb432eef475480a2a5749ae (diff)
downloadpytest-1e5b21cd6180009939130f6169c936427d0d4572.tar.gz
Fix memory leak with pytest.raises by using weakref
-rw-r--r--AUTHORS1
-rw-r--r--CHANGELOG.rst3
-rw-r--r--_pytest/_code/code.py5
3 files changed, 7 insertions, 2 deletions
diff --git a/AUTHORS b/AUTHORS
index 378bac5a4..6de0a112b 100644
--- a/AUTHORS
+++ b/AUTHORS
@@ -99,6 +99,7 @@ mbyt
Michael Aquilina
Michael Birtwell
Michael Droettboom
+Michael Seifert
Mike Lundy
Nicolas Delaby
Oleg Pidsadnyi
diff --git a/CHANGELOG.rst b/CHANGELOG.rst
index 5dada862a..fb5395731 100644
--- a/CHANGELOG.rst
+++ b/CHANGELOG.rst
@@ -12,6 +12,9 @@
* When loading plugins, import errors which contain non-ascii messages are now properly handled in Python 2 (`#1998`_).
Thanks `@nicoddemus`_ for the PR.
+* Fixed memory leak in the RaisesContext (pytest.raises) (`#1965`_).
+ Thanks `@MSeifert04`_ for the report the PR.
+
* Fixed false-positives warnings from assertion rewrite hook for modules that were rewritten but
were later marked explicitly by ``pytest.register_assert_rewrite``
or implicitly as a plugin (`#2005`_).
diff --git a/_pytest/_code/code.py b/_pytest/_code/code.py
index 416ee0b1b..5b4237939 100644
--- a/_pytest/_code/code.py
+++ b/_pytest/_code/code.py
@@ -1,6 +1,7 @@
import sys
from inspect import CO_VARARGS, CO_VARKEYWORDS
import re
+from weakref import ref
import py
builtin_repr = repr
@@ -230,7 +231,7 @@ class TracebackEntry(object):
return False
if py.builtin.callable(tbh):
- return tbh(self._excinfo)
+ return tbh(None if self._excinfo is None else self._excinfo())
else:
return tbh
@@ -370,7 +371,7 @@ class ExceptionInfo(object):
#: the exception type name
self.typename = self.type.__name__
#: the exception traceback (_pytest._code.Traceback instance)
- self.traceback = _pytest._code.Traceback(self.tb, excinfo=self)
+ self.traceback = _pytest._code.Traceback(self.tb, excinfo=ref(self))
def __repr__(self):
return "<ExceptionInfo %s tblen=%d>" % (self.typename, len(self.traceback))