Commit 3837d979 authored by Victor Stinner's avatar Victor Stinner Committed by GitHub

bpo-15526: test_startfile changes the cwd (#1537)

Try to fix test_startfile's inability to clean up after itself in
time. Patch by Jeremy Kloth.

Fix the following support.rmtree() error while trying to remove the
temporary working directory used by Python tests:

WindowsError: [Error 32] The process cannot access the file because
it is being used by another process: ...

Original commit: 8a53dbeb
parent 05469fa1
......@@ -10,8 +10,8 @@
import unittest
from test import test_support
import os
import sys
from os import path
from time import sleep
startfile = test_support.get_attribute(os, 'startfile')
......@@ -23,20 +23,23 @@ class TestCase(unittest.TestCase):
def test_nonexisting_u(self):
self.assertRaises(OSError, startfile, u"nonexisting.vbs")
def check_empty(self, empty):
# We need to make sure the child process starts in a directory
# we're not about to delete. If we're running under -j, that
# means the test harness provided directory isn't a safe option.
# See http://bugs.python.org/issue15526 for more details
with test_support.change_cwd(path.dirname(sys.executable)):
startfile(empty)
startfile(empty, "open")
def test_empty(self):
empty = path.join(path.dirname(__file__), "empty.vbs")
startfile(empty)
startfile(empty, "open")
# Give the child process some time to exit before we finish.
# Otherwise the cleanup code will not be able to delete the cwd,
# because it is still in use.
sleep(0.1)
def test_empty_u(self):
self.check_empty(empty)
def test_empty_unicode(self):
empty = path.join(path.dirname(__file__), "empty.vbs")
startfile(unicode(empty, "mbcs"))
startfile(unicode(empty, "mbcs"), "open")
sleep(0.1)
empty = unicode(empty, "mbcs")
self.check_empty(empty)
def test_main():
test_support.run_unittest(TestCase)
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment