Rietveld Code Review Tool
Help | Bug tracker | Discussion group | Source code | Sign in
(7)

Delta Between Two Patch Sets: Lib/unittest/case.py

Issue 19817: tracemalloc add a memory limit feature
Left Patch Set: Created 6 years, 6 months ago
Right Patch Set: Created 6 years, 6 months ago
Left:
Right:
Use n/p to move between diff chunks; N/P to move between comments. Please Sign in to add in-line comments.
Jump to:
Right: Side by side diff | Download
« no previous file with change/comment | « Lib/threading.py ('k') | no next file » | no next file with change/comment »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
LEFTRIGHT
(no file at all)
1 """Test case implementation""" 1 """Test case implementation"""
2 2
3 import sys 3 import sys
4 import functools 4 import functools
5 import difflib 5 import difflib
6 import logging 6 import logging
7 import pprint 7 import pprint
8 import re 8 import re
9 import warnings 9 import warnings
10 import collections 10 import collections
11 import contextlib 11 import contextlib
12 import tracemalloc
13 import random
12 14
13 from . import result 15 from . import result
14 from .util import (strclass, safe_repr, _count_diff_all_purpose, 16 from .util import (strclass, safe_repr, _count_diff_all_purpose,
15 _count_diff_hashable, _common_shorten_repr) 17 _count_diff_hashable, _common_shorten_repr)
16 18
17 __unittest = True 19 __unittest = True
18 20
19 21
20 DIFF_OMITTED = ('\nDiff is %s characters long. ' 22 DIFF_OMITTED = ('\nDiff is %s characters long. '
21 'Set self.maxDiff to None to see it.') 23 'Set self.maxDiff to None to see it.')
(...skipping 538 matching lines...) Expand 10 before | Expand all | Expand 10 after
560 expecting_failure = getattr(testMethod, 562 expecting_failure = getattr(testMethod,
561 "__unittest_expecting_failure__", False) 563 "__unittest_expecting_failure__", False)
562 try: 564 try:
563 outcome = _Outcome(result) 565 outcome = _Outcome(result)
564 self._outcome = outcome 566 self._outcome = outcome
565 567
566 with outcome.testPartExecutor(self): 568 with outcome.testPartExecutor(self):
567 self.setUp() 569 self.setUp()
568 if outcome.success: 570 if outcome.success:
569 outcome.expecting_failure = expecting_failure 571 outcome.expecting_failure = expecting_failure
572 limit = random.randint(100, 1024*50)
570 with outcome.testPartExecutor(self, isTest=True): 573 with outcome.testPartExecutor(self, isTest=True):
571 testMethod() 574 tracemalloc.start(memory_limit=limit)
575 try:
576 testMethod()
577 finally:
578 tracemalloc.stop()
572 outcome.expecting_failure = False 579 outcome.expecting_failure = False
573 with outcome.testPartExecutor(self): 580 with outcome.testPartExecutor(self):
574 self.tearDown() 581 self.tearDown()
575 582
576 self.doCleanups() 583 self.doCleanups()
577 for test, reason in outcome.skipped: 584 for test, reason in outcome.skipped:
578 self._addSkip(result, test, reason) 585 self._addSkip(result, test, reason)
579 self._feedErrorsToResult(result, outcome.errors) 586 self._feedErrorsToResult(result, outcome.errors)
580 if outcome.success: 587 if outcome.success:
581 if expecting_failure: 588 if expecting_failure:
(...skipping 794 matching lines...) Expand 10 before | Expand all | Expand 10 after
1376 return "{} {}".format(self.test_case.id(), self._subDescription()) 1383 return "{} {}".format(self.test_case.id(), self._subDescription())
1377 1384
1378 def shortDescription(self): 1385 def shortDescription(self):
1379 """Returns a one-line description of the subtest, or None if no 1386 """Returns a one-line description of the subtest, or None if no
1380 description has been provided. 1387 description has been provided.
1381 """ 1388 """
1382 return self.test_case.shortDescription() 1389 return self.test_case.shortDescription()
1383 1390
1384 def __str__(self): 1391 def __str__(self):
1385 return "{} {}".format(self.test_case, self._subDescription()) 1392 return "{} {}".format(self.test_case, self._subDescription())
LEFTRIGHT

RSS Feeds Recent Issues | This issue
This is Rietveld 894c83f36cb7+