Skip to content

garbage collect test reference. #129

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 3 commits into from
Feb 8, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 20 additions & 0 deletions tests/testsuite.py
Original file line number Diff line number Diff line change
Expand Up @@ -111,6 +111,13 @@ def __call__(self, result):
def test_pass(self):
pass

class DummyRefCountTest(unittest.TestCase):
class dummy(object):
pass
def test_fail(self):
inst = self.dummy()
self.assertTrue(False)

def setUp(self):
self.stream = StringIO()
self.outdir = mkdtemp()
Expand Down Expand Up @@ -439,3 +446,16 @@ def test_xmlrunner_error_in_call(self):
self._test_xmlrunner(suite)
testsuite_output = self.stream.getvalue()
self.assertIn('Exception: Massive fail', testsuite_output)

@unittest.skipIf(not hasattr(sys, 'getrefcount'),
'skip - PyPy does not have sys.getrefcount.')
@unittest.skipIf((3, 0) <= sys.version_info < (3, 4),
'skip - test not garbage collected. '
'https://bugs.python.org/issue11798.')
def test_xmlrunner_hold_traceback(self):
suite = unittest.TestSuite()
suite.addTest(self.DummyRefCountTest('test_fail'))
countBeforeTest = sys.getrefcount(self.DummyRefCountTest.dummy)
runner = self._test_xmlrunner(suite)
countAfterTest = sys.getrefcount(self.DummyRefCountTest.dummy)
self.assertEqual(countBeforeTest, countAfterTest)
16 changes: 11 additions & 5 deletions xmlrunner/result.py
Original file line number Diff line number Diff line change
Expand Up @@ -94,15 +94,21 @@ def __init__(self, test_result, test_method, outcome=SUCCESS, err=None, subTest=
self.test_result = test_result
self.outcome = outcome
self.elapsed_time = 0
self.err = err
if err:
if self.outcome != _TestInfo.SKIP:
self.test_exception_name = safe_unicode(err[0].__name__)
self.test_exception_message = safe_unicode(err[1])
else:
self.test_exception_message = safe_unicode(err)

self.stdout = test_result._stdout_data
self.stderr = test_result._stderr_data

self.test_description = self.test_result.getDescription(test_method)
self.test_exception_info = (
'' if outcome in (self.SUCCESS, self.SKIP)
else self.test_result._exc_info_to_string(
self.err, test_method)
err, test_method)
)

self.test_name = testcase_name(test_method)
Expand Down Expand Up @@ -419,18 +425,18 @@ def _report_testcase(test_result, xml_testsuite, xml_document):
if test_result.outcome != test_result.SKIP:
failure.setAttribute(
'type',
safe_unicode(test_result.err[0].__name__)
test_result.test_exception_name
)
failure.setAttribute(
'message',
safe_unicode(test_result.err[1])
test_result.test_exception_message
)
error_info = safe_unicode(test_result.get_error_info())
_XMLTestResult._createCDATAsections(
xml_document, failure, error_info)
else:
failure.setAttribute('type', 'skip')
failure.setAttribute('message', safe_unicode(test_result.err))
failure.setAttribute('message', test_result.test_exception_message)

_report_testcase = staticmethod(_report_testcase)

Expand Down