From 3029aa6558ac2f1bbba7d543006a356483a4b49e Mon Sep 17 00:00:00 2001 From: holger krekel Date: Sun, 10 Jan 2010 20:45:37 +0100 Subject: [PATCH] fix some "import py" test issues, and prevent "genscript" script from having dist-options --HG-- branch : trunk --- py/plugin/pytest_default.py | 2 ++ py/plugin/pytest_pytester.py | 16 +++++++++++++++- testing/plugin/test_pytest_capture.py | 8 +++----- testing/plugin/test_pytest_genscript.py | 6 +++--- testing/pytest/acceptance_test.py | 4 ++-- 5 files changed, 25 insertions(+), 11 deletions(-) diff --git a/py/plugin/pytest_default.py b/py/plugin/pytest_default.py index 5405fe4fb..b9975991e 100644 --- a/py/plugin/pytest_default.py +++ b/py/plugin/pytest_default.py @@ -5,6 +5,8 @@ import py try: import execnet + if not py.path.local(py.__file__).check(): + raise ImportError("") except ImportError: execnet = None else: diff --git a/py/plugin/pytest_pytester.py b/py/plugin/pytest_pytester.py index 0737f3a29..a2bff6deb 100644 --- a/py/plugin/pytest_pytester.py +++ b/py/plugin/pytest_pytester.py @@ -321,7 +321,21 @@ class TmpTestdir: return (sys.executable, "-c", source,) def runpython(self, script): - return self.run(py.std.sys.executable, script) + s = self._getsysprepend() + if s: + script.write(s + "\n" + script.read()) + return self.run(sys.executable, script) + + def _getsysprepend(self): + if not self.request.config.getvalue("toolsonpath"): + s = "import sys ; sys.path.insert(0, %r) ; " % str(py._dir.dirpath()) + else: + s = "" + return s + + def runpython_c(self, command): + command = self._getsysprepend() + command + return self.run(py.std.sys.executable, "-c", command) def runpytest(self, *args): p = py.path.local.make_numbered_dir(prefix="runpytest-", diff --git a/testing/plugin/test_pytest_capture.py b/testing/plugin/test_pytest_capture.py index b928d8b79..93796f904 100644 --- a/testing/plugin/test_pytest_capture.py +++ b/testing/plugin/test_pytest_capture.py @@ -250,10 +250,8 @@ class TestLoggingInteraction: def test_capturing_and_logging_fundamentals(self, testdir): # here we check a fundamental feature - rootdir = str(py.path.local(py.__file__).dirpath().dirpath()) p = testdir.makepyfile(""" import sys, os - sys.path.insert(0, %r) import py, logging if hasattr(os, 'dup'): cap = py.io.StdCaptureFD(out=False, in_=False) @@ -262,7 +260,7 @@ class TestLoggingInteraction: logging.warn("hello1") outerr = cap.suspend() - print ("suspeneded and captured %%s" %% (outerr,)) + print ("suspeneded and captured %s" % (outerr,)) logging.warn("hello2") @@ -270,8 +268,8 @@ class TestLoggingInteraction: logging.warn("hello3") outerr = cap.suspend() - print ("suspend2 and captured %%s" %% (outerr,)) - """ % rootdir) + print ("suspend2 and captured %s" % (outerr,)) + """) result = testdir.runpython(p) assert result.stdout.fnmatch_lines([ "suspeneded and captured*hello1*", diff --git a/testing/plugin/test_pytest_genscript.py b/testing/plugin/test_pytest_genscript.py index de9156cf1..5cb768210 100644 --- a/testing/plugin/test_pytest_genscript.py +++ b/testing/plugin/test_pytest_genscript.py @@ -31,7 +31,7 @@ def test_rundist(testdir, standalone): pass """) result = standalone.run(sys.executable, testdir, '-n', '3') - assert result.ret == 0 - result.stdout.fnmatch_lines([ - "*1 passed*" + assert result.ret == 2 + result.stderr.fnmatch_lines([ + "*no such option*" ]) diff --git a/testing/pytest/acceptance_test.py b/testing/pytest/acceptance_test.py index 5300ebb87..b6e31c30e 100644 --- a/testing/pytest/acceptance_test.py +++ b/testing/pytest/acceptance_test.py @@ -81,11 +81,11 @@ class TestGeneralUsage: import py assert hasattr(py.test, 'mark') """) - result = testdir._run(sys.executable, p) + result = testdir.runpython(p) assert result.ret == 0 def test_pydoc(self, testdir): - result = testdir._run(sys.executable, "-c", "import py ; help(py.test)") + result = testdir.runpython_c("import py ; help(py.test)") assert result.ret == 0 s = result.stdout.str() assert 'MarkGenerator' in s