Skip to content
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

fix: fix _precache memory leak from LazySuite #1054

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
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
26 changes: 14 additions & 12 deletions nose/suite.py
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,7 @@ def __hash__(self):

def addTest(self, test):
self._precache.append(test)
self._had_precache = True

# added to bypass run changes in 2.7's unittest
def run(self, result):
Expand All @@ -79,28 +80,29 @@ def __nonzero__(self):
log.debug("tests in %s?", id(self))
if self._precache:
return True
if self.test_generator is None:
return False
try:
test = self.test_generator.next()
if test is not None:
self._precache.append(test)
return True
except StopIteration:
pass
return False
if self.test_generator is not None:
try:
test = self.test_generator.next()
if test is not None:
self.addTest(test)
return True
except StopIteration:
pass

return self._had_precache

def _get_tests(self):
log.debug("precache is %s", self._precache)
for test in self._precache:
yield test
while self._precache:
yield self._precache.pop(0)
if self.test_generator is None:
return
for test in self.test_generator:
yield test

def _set_tests(self, tests):
self._precache = []
self._had_precache = False
is_suite = isinstance(tests, unittest.TestSuite)
if callable(tests) and not is_suite:
self.test_generator = tests()
Expand Down