document explicitly clearing local references to pytest.raises() results
pytest.raises() returns an ExceptionInfo object which, if a local reference is made to it, forms a reference cycle: ExceptionInfo --> exception --> stack frame raising the exception --> current stack frame --> current local variables --> Exception Info Such a reference cycle would then prevent any local variables in the current stack frame, or any of its child stack frames involved in the same reference cycle, from being garbage collected until the next reference cycle garbage collection phase. This unnecessarily increases the program's memory footprint and potentially slows it down. This situation is based on a similar one described in the official 'try' statement Python documentation for locally stored exception references. --HG-- branch : document_ExceptionInfo_ref_cycle
This commit is contained in:
parent
618bd56acf
commit
ffffac27f9
|
@ -938,6 +938,12 @@ def raises(ExpectedException, *args, **kwargs):
|
|||
|
||||
This helper produces a ``py.code.ExceptionInfo()`` object.
|
||||
|
||||
Note that any local references made to such returned
|
||||
``py.code.ExceptionInfo()`` objects should be explicitly cleared, as they
|
||||
are part of a reference cycle similar to local references to caught Python
|
||||
exception objects. See the official Python ``try`` statement documentation
|
||||
for more detailed information.
|
||||
|
||||
If using Python 2.5 or above, you may use this function as a
|
||||
context manager::
|
||||
|
||||
|
|
Loading…
Reference in New Issue