MCPcopy Index your code
hub / github.com/python/cpython / test_nonexisting_with_pipes

Method test_nonexisting_with_pipes

Lib/test/test_subprocess.py:1495–1534  ·  view source on GitHub ↗
(self)

Source from the content-addressed store, hash-verified

1493 stderr=subprocess.PIPE)
1494
1495 def test_nonexisting_with_pipes(self):
1496 # bpo-30121: Popen with pipes must close properly pipes on error.
1497 # Previously, os.close() was called with a Windows handle which is not
1498 # a valid file descriptor.
1499 #
1500 # Run the test in a subprocess to control how the CRT reports errors
1501 # and to get stderr content.
1502 try:
1503 import msvcrt
1504 msvcrt.CrtSetReportMode
1505 except (AttributeError, ImportError):
1506 self.skipTest("need msvcrt.CrtSetReportMode")
1507
1508 code = textwrap.dedent(f"""
1509 import msvcrt
1510 import subprocess
1511
1512 cmd = {NONEXISTING_CMD!r}
1513
1514 for report_type in [msvcrt.CRT_WARN,
1515 msvcrt.CRT_ERROR,
1516 msvcrt.CRT_ASSERT]:
1517 msvcrt.CrtSetReportMode(report_type, msvcrt.CRTDBG_MODE_FILE)
1518 msvcrt.CrtSetReportFile(report_type, msvcrt.CRTDBG_FILE_STDERR)
1519
1520 try:
1521 subprocess.Popen(cmd,
1522 stdout=subprocess.PIPE,
1523 stderr=subprocess.PIPE)
1524 except OSError:
1525 pass
1526 """)
1527 cmd = [sys.executable, "-c", code]
1528 proc = subprocess.Popen(cmd,
1529 stderr=subprocess.PIPE,
1530 universal_newlines=True)
1531 with proc:
1532 stderr = proc.communicate()[1]
1533 self.assertEqual(stderr, "")
1534 self.assertEqual(proc.returncode, 0)
1535
1536 def test_double_close_on_error(self):
1537 # Issue #18851

Callers

nothing calls this directly

Calls 4

communicateMethod · 0.95
skipTestMethod · 0.80
dedentMethod · 0.45
assertEqualMethod · 0.45

Tested by

no test coverage detected