fix some "import py" test issues, and prevent "genscript" script from having dist-options
--HG-- branch : trunk
This commit is contained in:
parent
45c1517580
commit
3029aa6558
|
@ -5,6 +5,8 @@ import py
|
||||||
|
|
||||||
try:
|
try:
|
||||||
import execnet
|
import execnet
|
||||||
|
if not py.path.local(py.__file__).check():
|
||||||
|
raise ImportError("")
|
||||||
except ImportError:
|
except ImportError:
|
||||||
execnet = None
|
execnet = None
|
||||||
else:
|
else:
|
||||||
|
|
|
@ -321,7 +321,21 @@ class TmpTestdir:
|
||||||
return (sys.executable, "-c", source,)
|
return (sys.executable, "-c", source,)
|
||||||
|
|
||||||
def runpython(self, script):
|
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):
|
def runpytest(self, *args):
|
||||||
p = py.path.local.make_numbered_dir(prefix="runpytest-",
|
p = py.path.local.make_numbered_dir(prefix="runpytest-",
|
||||||
|
|
|
@ -250,10 +250,8 @@ class TestLoggingInteraction:
|
||||||
|
|
||||||
def test_capturing_and_logging_fundamentals(self, testdir):
|
def test_capturing_and_logging_fundamentals(self, testdir):
|
||||||
# here we check a fundamental feature
|
# here we check a fundamental feature
|
||||||
rootdir = str(py.path.local(py.__file__).dirpath().dirpath())
|
|
||||||
p = testdir.makepyfile("""
|
p = testdir.makepyfile("""
|
||||||
import sys, os
|
import sys, os
|
||||||
sys.path.insert(0, %r)
|
|
||||||
import py, logging
|
import py, logging
|
||||||
if hasattr(os, 'dup'):
|
if hasattr(os, 'dup'):
|
||||||
cap = py.io.StdCaptureFD(out=False, in_=False)
|
cap = py.io.StdCaptureFD(out=False, in_=False)
|
||||||
|
@ -262,7 +260,7 @@ class TestLoggingInteraction:
|
||||||
logging.warn("hello1")
|
logging.warn("hello1")
|
||||||
outerr = cap.suspend()
|
outerr = cap.suspend()
|
||||||
|
|
||||||
print ("suspeneded and captured %%s" %% (outerr,))
|
print ("suspeneded and captured %s" % (outerr,))
|
||||||
|
|
||||||
logging.warn("hello2")
|
logging.warn("hello2")
|
||||||
|
|
||||||
|
@ -270,8 +268,8 @@ class TestLoggingInteraction:
|
||||||
logging.warn("hello3")
|
logging.warn("hello3")
|
||||||
|
|
||||||
outerr = cap.suspend()
|
outerr = cap.suspend()
|
||||||
print ("suspend2 and captured %%s" %% (outerr,))
|
print ("suspend2 and captured %s" % (outerr,))
|
||||||
""" % rootdir)
|
""")
|
||||||
result = testdir.runpython(p)
|
result = testdir.runpython(p)
|
||||||
assert result.stdout.fnmatch_lines([
|
assert result.stdout.fnmatch_lines([
|
||||||
"suspeneded and captured*hello1*",
|
"suspeneded and captured*hello1*",
|
||||||
|
|
|
@ -31,7 +31,7 @@ def test_rundist(testdir, standalone):
|
||||||
pass
|
pass
|
||||||
""")
|
""")
|
||||||
result = standalone.run(sys.executable, testdir, '-n', '3')
|
result = standalone.run(sys.executable, testdir, '-n', '3')
|
||||||
assert result.ret == 0
|
assert result.ret == 2
|
||||||
result.stdout.fnmatch_lines([
|
result.stderr.fnmatch_lines([
|
||||||
"*1 passed*"
|
"*no such option*"
|
||||||
])
|
])
|
||||||
|
|
|
@ -81,11 +81,11 @@ class TestGeneralUsage:
|
||||||
import py
|
import py
|
||||||
assert hasattr(py.test, 'mark')
|
assert hasattr(py.test, 'mark')
|
||||||
""")
|
""")
|
||||||
result = testdir._run(sys.executable, p)
|
result = testdir.runpython(p)
|
||||||
assert result.ret == 0
|
assert result.ret == 0
|
||||||
|
|
||||||
def test_pydoc(self, testdir):
|
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
|
assert result.ret == 0
|
||||||
s = result.stdout.str()
|
s = result.stdout.str()
|
||||||
assert 'MarkGenerator' in s
|
assert 'MarkGenerator' in s
|
||||||
|
|
Loading…
Reference in New Issue