fix some "import py" test issues, and prevent "genscript" script from having dist-options

--HG--
branch : trunk
This commit is contained in:
holger krekel 2010-01-10 20:45:37 +01:00
parent 45c1517580
commit 3029aa6558
5 changed files with 25 additions and 11 deletions

View File

@ -5,6 +5,8 @@ import py
try:
import execnet
if not py.path.local(py.__file__).check():
raise ImportError("")
except ImportError:
execnet = None
else:

View File

@ -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-",

View File

@ -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*",

View File

@ -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*"
])

View File

@ -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