New submission from Dave Fugate <dfug...@microsoft.com>:

Sprinkled throughout CPython's test modules are snippets of code such as the 
following taken from 2.7A3's test_old_mailbox.py (line 141):
    box = mailbox.UnixMailbox(open(self._path, 'r'))

The key thing to observe here is the file being opened yet never has it's 
'close' method explicitly called.  While this is fine for CPython's rather 
predictable garbage collections, it's quite possible that in alternate 
implementations of Python this file object won't be destroyed until well after 
line 141.  This can result in seemingly random failures of CPython's tests 
under alternate implementations of Python.

The solution to this problem would be to consistently use the 'with' statement 
(or alternatively close all open file objects) throughout all CPython test 
modules.

I've gone ahead and submitted an updated (2.7A3) version of test_old_mailbox.py 
which addresses this.  We can find other places where this is going on as well, 
but for the most part the tests already seem to be doing the right thing.

----------
components: Tests
files: test_old_mailbox.py
messages: 99425
nosy: midnightdf
severity: normal
status: open
title: Use the 'with' statement in conjunction with 'open' throughout test 
modules
type: feature request
versions: Python 2.6, Python 2.7
Added file: http://bugs.python.org/file16235/test_old_mailbox.py

_______________________________________
Python tracker <rep...@bugs.python.org>
<http://bugs.python.org/issue7944>
_______________________________________
_______________________________________________
Python-bugs-list mailing list
Unsubscribe: 
http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com

Reply via email to