#7712: add a temp_cwd context manager to test_support and use it in regrtest to run all the tests in a temporary directory, saving the original CWD in test_support.SAVEDCWD. Thanks to Florent Xicluna who helped with the patch.
diff --git a/Lib/test/test_subprocess.py b/Lib/test/test_subprocess.py
index db93393..cef4300 100644
--- a/Lib/test/test_subprocess.py
+++ b/Lib/test/test_subprocess.py
@@ -7,6 +7,7 @@
import tempfile
import time
import re
+import sysconfig
mswindows = (sys.platform == "win32")
@@ -140,9 +141,21 @@
p.wait()
self.assertEqual(p.stderr, None)
- def test_executable(self):
- p = subprocess.Popen(["somethingyoudonthave",
- "-c", "import sys; sys.exit(47)"],
+ def test_executable_with_cwd(self):
+ python_dir = os.path.dirname(os.path.realpath(sys.executable))
+ p = subprocess.Popen(["somethingyoudonthave", "-c",
+ "import sys; sys.exit(47)"],
+ executable=sys.executable, cwd=python_dir)
+ p.wait()
+ self.assertEqual(p.returncode, 47)
+
+ @unittest.skipIf(sysconfig.is_python_build(),
+ "need an installed Python. See #7774")
+ def test_executable_without_cwd(self):
+ # For a normal installation, it should work without 'cwd'
+ # argument. For test runs in the build directory, see #7774.
+ p = subprocess.Popen(["somethingyoudonthave", "-c",
+ "import sys; sys.exit(47)"],
executable=sys.executable)
p.wait()
self.assertEqual(p.returncode, 47)