Skip to content

Commit 1248f81

Browse files
committed
Fix memory leak with pytest.raises by using weakref
1 parent de16149 commit 1248f81

3 files changed

Lines changed: 9 additions & 4 deletions

File tree

AUTHORS

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -97,6 +97,7 @@ mbyt
9797
Michael Aquilina
9898
Michael Birtwell
9999
Michael Droettboom
100+
Michael Seifert
100101
Mike Lundy
101102
Nicolas Delaby
102103
Oleg Pidsadnyi

CHANGELOG.rst

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,9 @@
99
* When loading plugins, import errors which contain non-ascii messages are now properly handled in Python 2 (`#1998`_).
1010
Thanks `@nicoddemus`_ for the PR.
1111

12+
* Fixed memory leak in the RaisesContext (pytest.raises) (`#1965`_).
13+
Thanks `@MSeifert04`_ for the report the PR.
14+
1215
*
1316

1417

@@ -81,7 +84,7 @@
8184
enabled. This allows proper post mortem debugging for all applications
8285
which have significant logic in their tearDown machinery (`#1890`_). Thanks
8386
`@mbyt`_ for the PR.
84-
87+
8588
* Fix use of deprecated ``getfuncargvalue`` method in the internal doctest plugin.
8689
Thanks `@ViviCoder`_ for the report (`#1898`_).
8790

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

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

384387
* Always include full assertion explanation. The previous behaviour was hiding

_pytest/_code/code.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import sys
22
from inspect import CO_VARARGS, CO_VARKEYWORDS
33
import re
4+
from weakref import ref
45

56
import py
67
builtin_repr = repr
@@ -230,7 +231,7 @@ def ishidden(self):
230231
return False
231232

232233
if py.builtin.callable(tbh):
233-
return tbh(self._excinfo)
234+
return tbh(None if self._excinfo is None else self._excinfo())
234235
else:
235236
return tbh
236237

@@ -370,7 +371,7 @@ def __init__(self, tup=None, exprinfo=None):
370371
#: the exception type name
371372
self.typename = self.type.__name__
372373
#: the exception traceback (_pytest._code.Traceback instance)
373-
self.traceback = _pytest._code.Traceback(self.tb, excinfo=self)
374+
self.traceback = _pytest._code.Traceback(self.tb, excinfo=ref(self))
374375

375376
def __repr__(self):
376377
return "<ExceptionInfo %s tblen=%d>" % (self.typename, len(self.traceback))

0 commit comments

Comments
 (0)