[Python-Dev] fixing tests on windows

Giampaolo Rodola' gnewsg at gmail.com
Tue Apr 1 21:09:56 CEST 2008


On 1 Apr, 21:03, "Giampaolo Rodola'" <gne... at gmail.com> wrote:
> On 1 Apr, 18:27, "Steven Bethard" <steven.beth... at gmail.com> wrote:
>> > On Tue, Apr 1, 2008 at 10:20 AM, Facundo Batista
>> > <facundobati... at gmail.com> wrote:
> > > 2008年4月1日, Tim Golden <m... at timgolden.me.uk>:
> > >  >  If this is the thing to do, presumably test_support should
> > >  >  grow a "remove_file" which does something of this sort?
>> > >  +1 (I was thinking exactly that).
>> > +1 here too. That looks like a great solution.  Of course, once it's
> > in test_support, we need to fix *all* file removals in the test suite.
> > ;-)
>> > Steve
>> Why not just modifying test_support.unlink() like this?
> Surely more convenient than modifying the whole suite.
>> def unlink(filename):
>     try:
>         if os.name == 'nt':
>             os.rename(filename, filename + ".deleted")
>             filename = filename + ".deleted"
>         os.unlink(filename)
>     except OSError:
>         pass

Another solution, probably better:
def unlink(filename):
 try:
 os.unlink(filename)
 except OSError:
 if os.name == 'nt':
 try:
 os.rename(filename, filename + ".deleted")
 os.unlink(filename + ".deleted")
 except OSError:
 pass


More information about the Python-Dev mailing list

AltStyle によって変換されたページ (->オリジナル) /