summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorNed Batchelder <ned@nedbatchelder.com>2013-10-05 14:36:44 -0400
committerNed Batchelder <ned@nedbatchelder.com>2013-10-05 14:36:44 -0400
commitc5d684086456194adaedb36323ef4fafe7487a76 (patch)
treeda98ff140f649cd6c91ea3e6b42a3e721521a374
parent554ae8ae796348fb1a3e439967f0ef740b46772e (diff)
downloadpython-coveragepy-c5d684086456194adaedb36323ef4fafe7487a76.tar.gz
Can't just run 'python' in a subprocess from 3.x, since it doesn't install as 'python'.
-rw-r--r--tests/coveragetest.py8
-rw-r--r--tests/test_process.py6
2 files changed, 12 insertions, 2 deletions
diff --git a/tests/coveragetest.py b/tests/coveragetest.py
index 1cefb6e..9f7c79c 100644
--- a/tests/coveragetest.py
+++ b/tests/coveragetest.py
@@ -452,6 +452,14 @@ class CoverageTest(TestCase):
Returns the process' stdout text.
"""
+ # Running Python subprocesses can be tricky. Use the real name of our
+ # own executable. So "python foo.py" might get executed as
+ # "python3.3 foo.py". This is important because Python 3.x doesn't
+ # install as "python", so you might get a Python 2 executable instead
+ # if you don't use the executable's basename.
+ if cmd.startswith("python "):
+ cmd = os.path.basename(sys.executable) + cmd[6:]
+
_, output = self.run_command_status(cmd)
return output
diff --git a/tests/test_process.py b/tests/test_process.py
index 4409c69..c49d90a 100644
--- a/tests/test_process.py
+++ b/tests/test_process.py
@@ -598,10 +598,12 @@ class ProcessStartupTest(CoverageTest):
raise SkipTest(
"Can't test subprocess pth file suppport during metacoverage"
)
+
# Main will run sub.py
self.make_file("main.py", """\
- import os
- os.system("python sub.py")
+ import os, os.path, sys
+ ex = os.path.basename(sys.executable)
+ os.system(ex + " sub.py")
""")
# sub.py will write a few lines.
self.make_file("sub.py", """\