break reference cycles caused by storing local reference to exception info

Such reference cycles unnecessarily cause Python interpreter not to garbage
collect the objects referenced in those cycles as soon they could be collected,
and in turn cause the tests to use more memory than is strictly necessary.

--HG--
branch : break_ExceptionInfo_reference_cycles
This commit is contained in:
Jurko Gospodnetić 2014-04-02 15:34:36 +02:00
parent 36288c5134
commit 98ea8fae32
3 changed files with 4 additions and 4 deletions

View File

@ -149,11 +149,10 @@ def assertrepr_compare(config, op, left, right):
if istext(left) and istext(right):
explanation = _notin_text(left, right, verbose)
except Exception:
excinfo = py.code.ExceptionInfo()
explanation = [
u('(pytest_assertion plugin: representation of details failed. '
'Probably an object has a faulty __repr__.)'),
u(excinfo)]
u(py.code.ExceptionInfo())]
if not explanation:
return None

View File

@ -98,6 +98,7 @@ def wrap_session(config, doit):
if session._testsfailed:
session.exitstatus = EXIT_TESTSFAILED
finally:
excinfo = None # Explicitly break reference cycle.
session.startdir.chdir()
if initstate >= 2:
config.hook.pytest_sessionfinish(

View File

@ -456,8 +456,8 @@ class Module(pytest.File, PyCollector):
try:
mod = self.fspath.pyimport(ensuresyspath=True)
except SyntaxError:
excinfo = py.code.ExceptionInfo()
raise self.CollectError(excinfo.getrepr(style="short"))
raise self.CollectError(
py.code.ExceptionInfo().getrepr(style="short"))
except self.fspath.ImportMismatchError:
e = sys.exc_info()[1]
raise self.CollectError(