On 16/12/2012 21:18, Philip Jenvey wrote:
> On Dec 14, 2012, at 5:12 PM, Jeff Allen wrote:
>>> On Fri, Dec 14, 2012 at 12:59 AM, Jeff Allen<ja...py@...> wrote:
>>>> Second thoughts on the below ... tearDown is called, as it should be,
>>>> but in the particular test (test.test_fileio.AutoFileTests.testErrors)
>>>> that was at the root of the problem, a second file object (_io.FileIO)
>>>> is created on the same file and tearDown does not know about it.
>> Seems I was wrong about CPython getting away with this. I can get a
>> similar cascade of errors with CPython 3.3, if I deliberately introduce
>> an error into the tests. The code is full of close and unlink
>> statements, but PyPy has exactly the same file but IronPython defines
>> its own test (which consists mostly of TODO comments). The dilemma now
>> is how thorough to be about the OtherFileTest: done properly, with setUp
>> and tearDown, quite a lot of try...finally...unlink() can be removed (I
>> think). I'll put a changeset just for this in my next push (for Jython).
>> Tempting to do the same for CPython (via the bug tracker I mean).
> It sounds like you're on Windows, which exacerbates this problem. You can't remove files on Windows if any process still has an open fd on it, so things like unlink die with a hard error in cases like this. POSIX doesn't care and so it gets no error. Especially annoying when you're building the implementation of a module from scratch and are bound to have tons of errors =]
> Go ahead and fix the these tests to add the proper cleanup if you'd like. Python 3.2 added a new ResourceWarning that's triggered when a file is implicitly closed, that can help you find cases like this (unfortunately we lack it for 2.7).
> 2.7's unittest added a nice feature for adding cleanups inside of the test case itself, a TestCase method addCleanup(). e.g.
> def test_stuff(self):
> f = open('file')
> self.addCleanup(f.close) # teardown will close it
Oh that's how that works! Yes I'm on Windows: quite a few things work
differently there and I have the impression Jython and CPython have not
been tested as thoroughly there.
I've already pushed my change for this:
http://hg.python.org/jython/rev/31ec07bf1be0 . The hunks are badly
chosen in this display, because of changed indentation, which you'll
hopefully be able to read through. The change isn't as big as it looks,
though I agree addCleanup is neater.
I should probably get a Linux box (real or virtual) for testing. As it
is, it would be useful if someone could check my work on *nix.