Merged in jurko/pytest/document_ExceptionInfo_ref_cycle (pull request #109)

document explicitly clearing local references to pytest.raises() results (redo of pull request #98)
This commit is contained in:
holger krekel 2014-01-23 11:42:51 +01:00
commit 245d39f52d
1 changed files with 16 additions and 0 deletions

View File

@ -962,6 +962,22 @@ def raises(ExpectedException, *args, **kwargs):
>>> raises(ZeroDivisionError, "f(0)")
<ExceptionInfo ...>
Performance note:
-----------------
Similar to caught exception objects in Python, explicitly clearing local
references to returned ``py.code.ExceptionInfo`` objects can help the Python
interpreter speed up its garbage collection.
Clearing those references breaks a reference cycle (``ExceptionInfo`` -->
caught exception --> frame stack raising the exception --> current frame
stack --> local variables --> ``ExceptionInfo``) which makes Python keep all
objects referenced from that cycle (including all local variables in the
current frame) alive until the next cyclic garbage collection run. See the
official Python ``try`` statement documentation for more detailed
information.
"""
__tracebackhide__ = True
if ExpectedException is AssertionError: