[Python-Dev] More joy with test_strptime (original) (raw)

Tim Peters tim.peters at gmail.com
Mon Jul 12 05:02:50 CEST 2004


FWIW, this is a minimal failing set of tests to run:

test___all__ test_site test_strptime

Remove either of the first two, and test_strptime passes here. Leave them both in, and test_strptime fails here, and whether or not .pyc files are deleted first.

If I put "return" as the first line of test_site.py's test_addpackage and test_addsitedir, the problem goes away. I don't know why, but believe that then no instance of class PthFile ever gets created.

I don't know whether it's relevant, but PthFile.cleanup's code like:

    try:
        os.remove(self.file_path)
    except OSError:
        pass

is almost never a correct thing to do, because it hides errors if the code is confused. If the intent is to ensure that the file doesn't exist, much better is

if os.path.exists(self.file_path):
    os.remove(self.file_path)

Then that raises an error if the code incorrectly (on Windows!) tries to delete a file that's still open. But I don't think that's happening here.

If I change PthFile.init's

    self.imported = "time"

to

    self.imported = "socket"

the problem also goes away. Ditto if I change it to

    self.imported = "re"

etc. So now I'm suspecting that the tricks in PthFile are managing to create a second instance of the time module not related to the instance of the time module test_strptime is monkey-patching with its

        time.tzname = (tz_name, tz_name)
        time.daylight = 1

tricks. But if so, I'm at a loss to explain why this would only happen on Windows. Is it the case that test_strptime is only failing on Windows?



More information about the Python-Dev mailing list