Skip to content

Commit

Permalink
Fix memory leak with pytest.raises by using weakref
Browse files Browse the repository at this point in the history
  • Loading branch information
MSeifert04 committed Oct 17, 2016
1 parent de16149 commit 1248f81
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 4 deletions.
1 change: 1 addition & 0 deletions AUTHORS
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,7 @@ mbyt
Michael Aquilina
Michael Birtwell
Michael Droettboom
Michael Seifert
Mike Lundy
Nicolas Delaby
Oleg Pidsadnyi
Expand Down
7 changes: 5 additions & 2 deletions CHANGELOG.rst
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,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.

*


Expand Down Expand Up @@ -81,7 +84,7 @@
enabled. This allows proper post mortem debugging for all applications
which have significant logic in their tearDown machinery (`#1890`_). Thanks
`@mbyt`_ for the PR.

* Fix use of deprecated ``getfuncargvalue`` method in the internal doctest plugin.
Thanks `@ViviCoder`_ for the report (`#1898`_).

Expand Down Expand Up @@ -378,7 +381,7 @@ time or change existing behaviors in order to make them less surprising/more use

* Refined logic for determining the ``rootdir``, considering only valid
paths which fixes a number of issues: `#1594`_, `#1435`_ and `#1471`_.
Updated the documentation according to current behavior. Thanks to
Updated the documentation according to current behavior. Thanks to
`@blueyed`_, `@davehunt`_ and `@matthiasha`_ for the PR.

* Always include full assertion explanation. The previous behaviour was hiding
Expand Down
5 changes: 3 additions & 2 deletions _pytest/_code/code.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import sys
from inspect import CO_VARARGS, CO_VARKEYWORDS
import re
from weakref import ref

import py
builtin_repr = repr
Expand Down Expand Up @@ -230,7 +231,7 @@ def ishidden(self):
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

Expand Down Expand Up @@ -370,7 +371,7 @@ def __init__(self, tup=None, exprinfo=None):
#: 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))
Expand Down

0 comments on commit 1248f81

Please sign in to comment.