Skip to content

Commit c80504f

Browse files
committed
Fix ProcessTestCasePOSIXPurePython to test the module from import when
_posixsubprocess doesn't exist rather than simply stubbing it out after the fact. This adds coverage for the RuntimeWarning as well as using the pure python _create_pipe instead of using _posixsubprocess.cloexec_pipe unintentionally with the pure python code. Ironically: I don't think any platform should ever actually _use_ the pure Python subprocess code on POSIX platforms anymore. This at least tests it properly in this stable branch. The pure python code for this is likely to be removed in 3.3.
1 parent e4eed06 commit c80504f

1 file changed

Lines changed: 17 additions & 9 deletions

File tree

Lib/test/test_subprocess.py

Lines changed: 17 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1498,15 +1498,23 @@ def tearDown(self):
14981498
@unittest.skipUnless(getattr(subprocess, '_posixsubprocess', False),
14991499
"_posixsubprocess extension module not found.")
15001500
class ProcessTestCasePOSIXPurePython(ProcessTestCase, POSIXProcessTestCase):
1501-
def setUp(self):
1502-
subprocess._posixsubprocess = None
1503-
ProcessTestCase.setUp(self)
1504-
POSIXProcessTestCase.setUp(self)
1505-
1506-
def tearDown(self):
1507-
subprocess._posixsubprocess = sys.modules['_posixsubprocess']
1508-
POSIXProcessTestCase.tearDown(self)
1509-
ProcessTestCase.tearDown(self)
1501+
@classmethod
1502+
def setUpClass(cls):
1503+
global subprocess
1504+
assert subprocess._posixsubprocess
1505+
# Reimport subprocess while forcing _posixsubprocess to not exist.
1506+
with support.check_warnings(('.*_posixsubprocess .* not being used.*',
1507+
RuntimeWarning)):
1508+
subprocess = support.import_fresh_module(
1509+
'subprocess', blocked=['_posixsubprocess'])
1510+
assert not subprocess._posixsubprocess
1511+
1512+
@classmethod
1513+
def tearDownClass(cls):
1514+
global subprocess
1515+
# Reimport subprocess as it should be, restoring order to the universe.
1516+
subprocess = support.import_fresh_module('subprocess')
1517+
assert subprocess._posixsubprocess
15101518

15111519

15121520
class HelperFunctionTests(unittest.TestCase):

0 commit comments

Comments
 (0)