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

#26325: Add helper to check that no ResourceWarning is emitted

Can't Edit
Can't Publish+Mail
Start Review
Created:
3 years, 7 months ago by storchaka+cpython
Modified:
3 years, 7 months ago
Reviewers:
victor.stinner
CC:
haypo, devnull_psf.upfronthosting.co.za, Martin Panter, storchaka
Visibility:
Public.

Patch Set 1 #

Total comments: 2

Patch Set 2 #

Unified diffs Side-by-side diffs Delta from patch set Stats Patch
Lib/test/support/__init__.py View 1 2 chunks +23 lines, -1 line 0 comments Download
Lib/test/test_asyncio/test_subprocess.py View 1 1 chunk +1 line, -2 lines 0 comments Download
Lib/test/test_io.py View 1 2 chunks +3 lines, -9 lines 0 comments Download
Lib/test/test_xml_etree.py View 1 2 chunks +2 lines, -8 lines 0 comments Download

Messages

Total messages: 1
victor.stinner_gmail.com
3 years, 7 months ago #1
http://bugs.python.org/review/26325/diff/16551/Lib/test/support/__init__.py
File Lib/test/support/__init__.py (right):

http://bugs.python.org/review/26325/diff/16551/Lib/test/support/__init__.py#n...
Lib/test/support/__init__.py:1154: def check_no_resource_warning(self):
I suggest to rename the "self" parameter to "testcase", it's not a method.

http://bugs.python.org/review/26325/diff/16551/Lib/test/support/__init__.py#n...
Lib/test/support/__init__.py:1155: """Context manager to check that no
ResourceWarning is emitted."""
The usage of the context manager is tricky: you should explain that you must
remove the object which may emit ResourceWarning before the end of the context
manager. For example, add bad/good examples:


Bad:

def test():
   with support.check_no_resource_warning():
      f = open(...)
      (...)
# ResourceWarning may be emitted when the function frame is destroyed

Good:

def test():
   with support.check_no_resource_warning():
      f = open(...)
      (...)
      f = None


You may also mention that it forces a garbage collection.

--

To check that the context manager is used correctly, you might add a variable
name parameter and check that the variable is deleted or set to None in the
parent frame... But I hate using frames, it always look like a hack :-p And
other Python implementations try to avoid creating frames.

Let's begin with a better doc ;-)
Sign in to reply to this message.

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