2008-08-16 23:26:59 +08:00
|
|
|
import py
|
|
|
|
|
|
|
|
pydir = py.path.local(py.__file__).dirpath()
|
|
|
|
pytestpath = pydir.join("bin", "py.test")
|
|
|
|
EXPECTTIMEOUT=10.0
|
|
|
|
|
2009-03-23 01:41:36 +08:00
|
|
|
class TestGeneralUsage:
|
2009-03-17 15:03:49 +08:00
|
|
|
def test_config_error(self, testdir):
|
|
|
|
testdir.makeconftest("""
|
|
|
|
class ConftestPlugin:
|
|
|
|
def pytest_configure(self, config):
|
|
|
|
raise config.Error("hello")
|
|
|
|
""")
|
|
|
|
result = testdir.runpytest(testdir.tmpdir)
|
|
|
|
assert result.ret != 0
|
|
|
|
assert result.stderr.fnmatch_lines([
|
2009-03-22 03:28:35 +08:00
|
|
|
'*ERROR: hello'
|
2009-03-17 15:03:49 +08:00
|
|
|
])
|
2009-03-17 18:29:45 +08:00
|
|
|
|
2009-04-18 02:09:29 +08:00
|
|
|
def test_config_preparse_plugin_option(self, testdir):
|
|
|
|
testdir.makepyfile(pytest_xyz="""
|
|
|
|
class XyzPlugin:
|
|
|
|
def pytest_addoption(self, parser):
|
|
|
|
parser.addoption("--xyz", dest="xyz", action="store")
|
|
|
|
""")
|
|
|
|
testdir.makepyfile(test_one="""
|
|
|
|
import py
|
|
|
|
def test_option():
|
|
|
|
assert py.test.config.option.xyz == "123"
|
|
|
|
""")
|
|
|
|
result = testdir.runpytest("-p", "xyz", "--xyz=123")
|
|
|
|
assert result.ret == 0
|
|
|
|
assert result.stdout.fnmatch_lines([
|
|
|
|
'*1 passed*',
|
|
|
|
])
|
|
|
|
|
2009-03-17 18:29:45 +08:00
|
|
|
def test_basetemp(self, testdir):
|
|
|
|
mytemp = testdir.tmpdir.mkdir("mytemp")
|
|
|
|
p = testdir.makepyfile("""
|
|
|
|
import py
|
|
|
|
def test_1():
|
|
|
|
py.test.ensuretemp('xyz')
|
|
|
|
""")
|
|
|
|
result = testdir.runpytest(p, '--basetemp=%s' %mytemp)
|
|
|
|
assert result.ret == 0
|
|
|
|
assert mytemp.join('xyz').check(dir=1)
|
2009-03-17 15:03:49 +08:00
|
|
|
|
2009-02-27 18:18:27 +08:00
|
|
|
def test_assertion_magic(self, testdir):
|
|
|
|
p = testdir.makepyfile("""
|
2008-08-16 23:26:59 +08:00
|
|
|
def test_this():
|
|
|
|
x = 0
|
|
|
|
assert x
|
|
|
|
""")
|
2009-02-27 18:18:27 +08:00
|
|
|
result = testdir.runpytest(p)
|
|
|
|
extra = result.stdout.fnmatch_lines([
|
2008-08-16 23:26:59 +08:00
|
|
|
"> assert x",
|
|
|
|
"E assert 0",
|
|
|
|
])
|
|
|
|
assert result.ret == 1
|
2009-03-17 15:03:49 +08:00
|
|
|
|
2009-02-27 18:18:27 +08:00
|
|
|
def test_collectonly_simple(self, testdir):
|
|
|
|
p = testdir.makepyfile("""
|
2008-08-16 23:26:59 +08:00
|
|
|
def test_func1():
|
|
|
|
pass
|
|
|
|
class TestClass:
|
|
|
|
def test_method(self):
|
|
|
|
pass
|
|
|
|
""")
|
2009-02-27 18:18:27 +08:00
|
|
|
result = testdir.runpytest("--collectonly", p)
|
|
|
|
stderr = result.stderr.str().strip()
|
|
|
|
assert stderr.startswith("inserting into sys.path")
|
2008-08-16 23:26:59 +08:00
|
|
|
assert result.ret == 0
|
2009-02-27 18:18:27 +08:00
|
|
|
extra = result.stdout.fnmatch_lines(py.code.Source("""
|
|
|
|
<Module '*.py'>
|
2008-08-16 23:26:59 +08:00
|
|
|
<Function 'test_func1'*>
|
|
|
|
<Class 'TestClass'>
|
|
|
|
<Instance '()'>
|
|
|
|
<Function 'test_method'*>
|
|
|
|
""").strip())
|
|
|
|
|
2009-02-27 18:18:27 +08:00
|
|
|
def test_collectonly_error(self, testdir):
|
|
|
|
p = testdir.makepyfile("import Errlkjqweqwe")
|
|
|
|
result = testdir.runpytest("--collectonly", p)
|
|
|
|
stderr = result.stderr.str().strip()
|
|
|
|
assert stderr.startswith("inserting into sys.path")
|
|
|
|
assert result.ret == 1
|
|
|
|
extra = result.stdout.fnmatch_lines(py.code.Source("""
|
|
|
|
<Module '*.py'>
|
|
|
|
*ImportError*
|
|
|
|
!!!*failures*!!!
|
|
|
|
*test_collectonly_error.py:1*
|
|
|
|
""").strip())
|
|
|
|
|
|
|
|
|
|
|
|
def test_nested_import_error(self, testdir):
|
|
|
|
p = testdir.makepyfile("""
|
2008-08-16 23:26:59 +08:00
|
|
|
import import_fails
|
|
|
|
def test_this():
|
|
|
|
assert import_fails.a == 1
|
2009-02-27 18:18:27 +08:00
|
|
|
""")
|
|
|
|
testdir.makepyfile(import_fails="import does_not_work")
|
|
|
|
result = testdir.runpytest(p)
|
|
|
|
extra = result.stdout.fnmatch_lines([
|
2008-08-16 23:26:59 +08:00
|
|
|
"> import import_fails",
|
|
|
|
"E ImportError: No module named does_not_work",
|
|
|
|
])
|
|
|
|
assert result.ret == 1
|
|
|
|
|
2009-02-27 18:18:27 +08:00
|
|
|
def test_skipped_reasons(self, testdir):
|
|
|
|
testdir.makepyfile(
|
2008-08-16 23:26:59 +08:00
|
|
|
test_one="""
|
|
|
|
from conftest import doskip
|
|
|
|
def setup_function(func):
|
|
|
|
doskip()
|
|
|
|
def test_func():
|
|
|
|
pass
|
|
|
|
class TestClass:
|
|
|
|
def test_method(self):
|
|
|
|
doskip()
|
|
|
|
""",
|
|
|
|
test_two = """
|
|
|
|
from conftest import doskip
|
|
|
|
doskip()
|
|
|
|
""",
|
|
|
|
conftest = """
|
|
|
|
import py
|
|
|
|
def doskip():
|
|
|
|
py.test.skip('test')
|
|
|
|
"""
|
|
|
|
)
|
2009-02-27 18:18:27 +08:00
|
|
|
result = testdir.runpytest()
|
|
|
|
extra = result.stdout.fnmatch_lines([
|
2008-08-16 23:26:59 +08:00
|
|
|
"*test_one.py ss",
|
2009-02-27 18:18:27 +08:00
|
|
|
"*test_two.py S",
|
2008-08-16 23:26:59 +08:00
|
|
|
"___* skipped test summary *_",
|
|
|
|
"*conftest.py:3: *3* Skipped: 'test'",
|
|
|
|
])
|
|
|
|
assert result.ret == 0
|
|
|
|
|
2009-02-27 18:18:27 +08:00
|
|
|
def test_deselected(self, testdir):
|
|
|
|
testpath = testdir.makepyfile("""
|
2008-08-16 23:26:59 +08:00
|
|
|
def test_one():
|
|
|
|
pass
|
|
|
|
def test_two():
|
|
|
|
pass
|
|
|
|
def test_three():
|
|
|
|
pass
|
2009-02-27 18:18:27 +08:00
|
|
|
"""
|
2008-08-16 23:26:59 +08:00
|
|
|
)
|
2009-02-27 18:18:27 +08:00
|
|
|
result = testdir.runpytest("-k", "test_two:", testpath)
|
|
|
|
extra = result.stdout.fnmatch_lines([
|
|
|
|
"*test_deselected.py ..",
|
2008-08-16 23:26:59 +08:00
|
|
|
"=* 1 test*deselected by 'test_two:'*=",
|
|
|
|
])
|
|
|
|
assert result.ret == 0
|
|
|
|
|
2009-02-27 18:18:27 +08:00
|
|
|
def test_no_skip_summary_if_failure(self, testdir):
|
|
|
|
testdir.makepyfile("""
|
2008-08-16 23:26:59 +08:00
|
|
|
import py
|
|
|
|
def test_ok():
|
|
|
|
pass
|
|
|
|
def test_fail():
|
|
|
|
assert 0
|
|
|
|
def test_skip():
|
|
|
|
py.test.skip("dontshow")
|
|
|
|
""")
|
2009-02-27 18:18:27 +08:00
|
|
|
result = testdir.runpytest()
|
|
|
|
assert result.stdout.str().find("skip test summary") == -1
|
2008-08-16 23:26:59 +08:00
|
|
|
assert result.ret == 1
|
|
|
|
|
2009-02-27 18:18:27 +08:00
|
|
|
def test_passes(self, testdir):
|
|
|
|
p1 = testdir.makepyfile("""
|
2008-08-16 23:26:59 +08:00
|
|
|
def test_passes():
|
|
|
|
pass
|
|
|
|
class TestClass:
|
|
|
|
def test_method(self):
|
|
|
|
pass
|
|
|
|
""")
|
|
|
|
old = p1.dirpath().chdir()
|
|
|
|
try:
|
2009-02-27 18:18:27 +08:00
|
|
|
result = testdir.runpytest()
|
2008-08-16 23:26:59 +08:00
|
|
|
finally:
|
|
|
|
old.chdir()
|
2009-02-27 18:18:27 +08:00
|
|
|
extra = result.stdout.fnmatch_lines([
|
|
|
|
"test_passes.py ..",
|
|
|
|
"* 2 pass*",
|
2008-08-16 23:26:59 +08:00
|
|
|
])
|
|
|
|
assert result.ret == 0
|
|
|
|
|
2009-02-27 18:18:27 +08:00
|
|
|
def test_header_trailer_info(self, testdir):
|
|
|
|
p1 = testdir.makepyfile("""
|
2008-08-16 23:26:59 +08:00
|
|
|
def test_passes():
|
|
|
|
pass
|
|
|
|
""")
|
2009-02-27 18:18:27 +08:00
|
|
|
result = testdir.runpytest()
|
2008-08-16 23:26:59 +08:00
|
|
|
verinfo = ".".join(map(str, py.std.sys.version_info[:3]))
|
2009-02-27 18:18:27 +08:00
|
|
|
extra = result.stdout.fnmatch_lines([
|
2008-08-16 23:26:59 +08:00
|
|
|
"*===== test session starts ====*",
|
2009-03-21 09:31:27 +08:00
|
|
|
"python: platform %s -- Python %s*" %(
|
|
|
|
py.std.sys.platform, verinfo), # , py.std.sys.executable),
|
2009-02-27 18:18:27 +08:00
|
|
|
"*test_header_trailer_info.py .",
|
|
|
|
"=* 1 passed in *.[0-9][0-9] seconds *=",
|
2008-08-16 23:26:59 +08:00
|
|
|
])
|
|
|
|
|
2009-02-27 18:18:27 +08:00
|
|
|
def test_traceback_failure(self, testdir):
|
|
|
|
p1 = testdir.makepyfile("""
|
2008-08-16 23:26:59 +08:00
|
|
|
def g():
|
|
|
|
return 2
|
|
|
|
def f(x):
|
|
|
|
assert x == g()
|
|
|
|
def test_onefails():
|
|
|
|
f(3)
|
|
|
|
""")
|
2009-02-27 18:18:27 +08:00
|
|
|
result = testdir.runpytest(p1)
|
|
|
|
result.stdout.fnmatch_lines([
|
|
|
|
"*test_traceback_failure.py F",
|
2008-08-16 23:26:59 +08:00
|
|
|
"====* FAILURES *====",
|
|
|
|
"____*____",
|
|
|
|
"",
|
|
|
|
" def test_onefails():",
|
|
|
|
"> f(3)",
|
|
|
|
"",
|
2009-02-27 18:18:27 +08:00
|
|
|
"*test_*.py:6: ",
|
2008-08-16 23:26:59 +08:00
|
|
|
"_ _ _ *",
|
|
|
|
#"",
|
|
|
|
" def f(x):",
|
|
|
|
"> assert x == g()",
|
|
|
|
"E assert 3 == 2",
|
|
|
|
"E + where 2 = g()",
|
|
|
|
"",
|
2009-02-27 18:18:27 +08:00
|
|
|
"*test_traceback_failure.py:4: AssertionError"
|
2008-08-16 23:26:59 +08:00
|
|
|
])
|
|
|
|
|
2009-02-27 18:18:27 +08:00
|
|
|
def test_capturing_outerr(self, testdir):
|
|
|
|
p1 = testdir.makepyfile("""
|
2008-08-16 23:26:59 +08:00
|
|
|
import sys
|
|
|
|
def test_capturing():
|
|
|
|
print 42
|
|
|
|
print >>sys.stderr, 23
|
|
|
|
def test_capturing_error():
|
|
|
|
print 1
|
|
|
|
print >>sys.stderr, 2
|
|
|
|
raise ValueError
|
|
|
|
""")
|
2009-02-27 18:18:27 +08:00
|
|
|
result = testdir.runpytest(p1)
|
|
|
|
result.stdout.fnmatch_lines([
|
|
|
|
"*test_capturing_outerr.py .F",
|
2008-08-16 23:26:59 +08:00
|
|
|
"====* FAILURES *====",
|
|
|
|
"____*____",
|
2009-02-27 18:18:27 +08:00
|
|
|
"*test_capturing_outerr.py:8: ValueError",
|
2008-08-16 23:26:59 +08:00
|
|
|
"*--- Captured stdout ---*",
|
|
|
|
"1",
|
|
|
|
"*--- Captured stderr ---*",
|
|
|
|
"2",
|
|
|
|
])
|
|
|
|
|
2009-02-27 18:18:27 +08:00
|
|
|
def test_showlocals(self, testdir):
|
|
|
|
p1 = testdir.makepyfile("""
|
2008-08-16 23:26:59 +08:00
|
|
|
def test_showlocals():
|
|
|
|
x = 3
|
|
|
|
y = "x" * 5000
|
|
|
|
assert 0
|
|
|
|
""")
|
2009-02-27 18:18:27 +08:00
|
|
|
result = testdir.runpytest(p1, '-l')
|
|
|
|
result.stdout.fnmatch_lines([
|
2008-08-16 23:26:59 +08:00
|
|
|
#"_ _ * Locals *",
|
|
|
|
"x* = 3",
|
|
|
|
"y* = 'xxxxxx*"
|
|
|
|
])
|
|
|
|
|
2009-03-23 01:41:36 +08:00
|
|
|
def test_verbose_reporting(self, testdir):
|
|
|
|
p1 = testdir.makepyfile("""
|
|
|
|
import py
|
|
|
|
def test_fail():
|
|
|
|
raise ValueError()
|
|
|
|
def test_pass():
|
|
|
|
pass
|
|
|
|
class TestClass:
|
|
|
|
def test_skip(self):
|
|
|
|
py.test.skip("hello")
|
|
|
|
def test_gen():
|
|
|
|
def check(x):
|
|
|
|
assert x == 1
|
|
|
|
yield check, 0
|
|
|
|
""")
|
|
|
|
result = testdir.runpytest(p1, '-v')
|
2009-03-25 19:50:57 +08:00
|
|
|
result.stdout.fnmatch_lines([
|
|
|
|
"*test_verbose_reporting.py:2: test_fail*FAIL*",
|
|
|
|
"*test_verbose_reporting.py:4: test_pass*PASS*",
|
|
|
|
"*test_verbose_reporting.py:7: TestClass.test_skip*SKIP*",
|
|
|
|
"*test_verbose_reporting.py:10: test_gen*FAIL*",
|
|
|
|
])
|
|
|
|
assert result.ret == 1
|
|
|
|
result = testdir.runpytest(p1, '-v', '-n 1')
|
2009-03-23 01:41:36 +08:00
|
|
|
result.stdout.fnmatch_lines([
|
|
|
|
"*FAIL*test_verbose_reporting.py:2: test_fail*",
|
|
|
|
])
|
|
|
|
assert result.ret == 1
|
|
|
|
|
|
|
|
class TestDistribution:
|
|
|
|
def test_dist_conftest_options(self, testdir):
|
|
|
|
p1 = testdir.tmpdir.ensure("dir", 'p1.py')
|
|
|
|
p1.dirpath("__init__.py").write("")
|
|
|
|
p1.dirpath("conftest.py").write(py.code.Source("""
|
|
|
|
print "importing conftest", __file__
|
|
|
|
import py
|
|
|
|
Option = py.test.config.Option
|
|
|
|
option = py.test.config.addoptions("someopt",
|
|
|
|
Option('--someopt', action="store_true", dest="someopt", default=False))
|
|
|
|
dist_rsync_roots = ['../dir']
|
|
|
|
print "added options", option
|
|
|
|
print "config file seen from conftest", py.test.config
|
|
|
|
"""))
|
|
|
|
p1.write(py.code.Source("""
|
|
|
|
import py, conftest
|
|
|
|
def test_1():
|
|
|
|
print "config from test_1", py.test.config
|
|
|
|
print "conftest from test_1", conftest.__file__
|
|
|
|
print "test_1: py.test.config.option.someopt", py.test.config.option.someopt
|
|
|
|
print "test_1: conftest", conftest
|
|
|
|
print "test_1: conftest.option.someopt", conftest.option.someopt
|
|
|
|
assert conftest.option.someopt
|
|
|
|
"""))
|
|
|
|
result = testdir.runpytest('-d', '--tx=popen', p1, '--someopt')
|
|
|
|
assert result.ret == 0
|
|
|
|
extra = result.stdout.fnmatch_lines([
|
|
|
|
"*1 passed*",
|
|
|
|
])
|
2008-08-16 23:26:59 +08:00
|
|
|
|
2009-03-23 01:41:36 +08:00
|
|
|
def test_manytests_to_one_popen(self, testdir):
|
2009-02-27 18:18:27 +08:00
|
|
|
p1 = testdir.makepyfile("""
|
2008-08-16 23:26:59 +08:00
|
|
|
import py
|
|
|
|
def test_fail0():
|
|
|
|
assert 0
|
|
|
|
def test_fail1():
|
|
|
|
raise ValueError()
|
|
|
|
def test_ok():
|
|
|
|
pass
|
|
|
|
def test_skip():
|
|
|
|
py.test.skip("hello")
|
|
|
|
""",
|
|
|
|
)
|
2009-03-21 09:31:27 +08:00
|
|
|
result = testdir.runpytest(p1, '-d', '--tx=popen', '--tx=popen')
|
2009-02-27 18:18:27 +08:00
|
|
|
result.stdout.fnmatch_lines([
|
2009-03-21 09:31:27 +08:00
|
|
|
"*1*popen*Python*",
|
|
|
|
"*2*popen*Python*",
|
2009-02-27 18:18:27 +08:00
|
|
|
"*2 failed, 1 passed, 1 skipped*",
|
2008-08-16 23:26:59 +08:00
|
|
|
])
|
|
|
|
assert result.ret == 1
|
|
|
|
|
2009-03-23 01:41:36 +08:00
|
|
|
def test_dist_conftest_specified(self, testdir):
|
2009-03-17 14:10:40 +08:00
|
|
|
p1 = testdir.makepyfile("""
|
|
|
|
import py
|
|
|
|
def test_fail0():
|
|
|
|
assert 0
|
|
|
|
def test_fail1():
|
|
|
|
raise ValueError()
|
|
|
|
def test_ok():
|
|
|
|
pass
|
|
|
|
def test_skip():
|
|
|
|
py.test.skip("hello")
|
|
|
|
""",
|
|
|
|
)
|
|
|
|
testdir.makeconftest("""
|
2009-03-22 09:19:57 +08:00
|
|
|
pytest_option_tx = 'popen popen popen'.split()
|
2009-03-17 14:10:40 +08:00
|
|
|
""")
|
|
|
|
result = testdir.runpytest(p1, '-d')
|
|
|
|
result.stdout.fnmatch_lines([
|
2009-03-21 09:31:27 +08:00
|
|
|
"*1*popen*Python*",
|
|
|
|
"*2*popen*Python*",
|
|
|
|
"*3*popen*Python*",
|
2009-03-17 14:10:40 +08:00
|
|
|
"*2 failed, 1 passed, 1 skipped*",
|
|
|
|
])
|
|
|
|
assert result.ret == 1
|
|
|
|
|
2009-02-27 18:18:27 +08:00
|
|
|
def test_dist_tests_with_crash(self, testdir):
|
2008-08-16 23:26:59 +08:00
|
|
|
if not hasattr(py.std.os, 'kill'):
|
|
|
|
py.test.skip("no os.kill")
|
|
|
|
|
2009-02-27 18:18:27 +08:00
|
|
|
p1 = testdir.makepyfile("""
|
2008-08-16 23:26:59 +08:00
|
|
|
import py
|
|
|
|
def test_fail0():
|
|
|
|
assert 0
|
|
|
|
def test_fail1():
|
|
|
|
raise ValueError()
|
|
|
|
def test_ok():
|
|
|
|
pass
|
|
|
|
def test_skip():
|
|
|
|
py.test.skip("hello")
|
|
|
|
def test_crash():
|
|
|
|
import time
|
|
|
|
import os
|
|
|
|
time.sleep(0.5)
|
|
|
|
os.kill(os.getpid(), 15)
|
|
|
|
"""
|
|
|
|
)
|
2009-03-22 09:19:57 +08:00
|
|
|
result = testdir.runpytest(p1, '-d', '--tx=3*popen')
|
2009-02-27 18:18:27 +08:00
|
|
|
result.stdout.fnmatch_lines([
|
2009-03-17 05:17:14 +08:00
|
|
|
"*popen*Python*",
|
|
|
|
"*popen*Python*",
|
|
|
|
"*popen*Python*",
|
2009-03-21 09:31:27 +08:00
|
|
|
"*node down*",
|
2009-02-27 18:18:27 +08:00
|
|
|
"*3 failed, 1 passed, 1 skipped*"
|
2008-08-16 23:26:59 +08:00
|
|
|
])
|
|
|
|
assert result.ret == 1
|
|
|
|
|
2009-03-23 01:41:36 +08:00
|
|
|
def test_distribution_rsyncdirs_example(self, testdir):
|
|
|
|
source = testdir.mkdir("source")
|
|
|
|
dest = testdir.mkdir("dest")
|
|
|
|
subdir = source.mkdir("example_pkg")
|
|
|
|
subdir.ensure("__init__.py")
|
|
|
|
p = subdir.join("test_one.py")
|
|
|
|
p.write("def test_5(): assert not __file__.startswith(%r)" % str(p))
|
|
|
|
result = testdir.runpytest("-d", "--rsyncdir=%(subdir)s" % locals(),
|
|
|
|
"--tx=popen//chdir=%(dest)s" % locals(), p)
|
|
|
|
assert result.ret == 0
|
2009-02-27 18:18:27 +08:00
|
|
|
result.stdout.fnmatch_lines([
|
2009-03-23 01:41:36 +08:00
|
|
|
"*1* *popen*platform*",
|
|
|
|
#"RSyncStart: [G1]",
|
|
|
|
#"RSyncFinished: [G1]",
|
|
|
|
"*1 passed*"
|
2008-08-16 23:26:59 +08:00
|
|
|
])
|
2009-03-23 01:41:36 +08:00
|
|
|
assert dest.join(subdir.basename).check(dir=1)
|
2008-08-16 23:26:59 +08:00
|
|
|
|
2009-03-23 04:44:45 +08:00
|
|
|
def test_dist_each(self, testdir):
|
|
|
|
interpreters = []
|
|
|
|
for name in ("python2.4", "python2.5"):
|
|
|
|
interp = py.path.local.sysfind(name)
|
|
|
|
if interp is None:
|
|
|
|
py.test.skip("%s not found" % name)
|
|
|
|
interpreters.append(interp)
|
|
|
|
|
|
|
|
testdir.makepyfile(__init__="", test_one="""
|
|
|
|
import sys
|
|
|
|
def test_hello():
|
|
|
|
print "%s...%s" % sys.version_info[:2]
|
|
|
|
assert 0
|
|
|
|
""")
|
|
|
|
args = ["--dist=each"]
|
|
|
|
args += ["--tx", "popen//python=%s" % interpreters[0]]
|
|
|
|
args += ["--tx", "popen//python=%s" % interpreters[1]]
|
|
|
|
result = testdir.runpytest(*args)
|
|
|
|
result.stdout.fnmatch_lines(["2...4"])
|
|
|
|
result.stdout.fnmatch_lines(["2...5"])
|
|
|
|
|
2008-08-16 23:26:59 +08:00
|
|
|
|
2009-02-27 18:18:27 +08:00
|
|
|
class TestInteractive:
|
|
|
|
def getspawn(self, tmpdir):
|
2008-09-21 23:15:28 +08:00
|
|
|
pexpect = py.test.importorskip("pexpect")
|
2009-03-17 21:10:17 +08:00
|
|
|
basetemp = tmpdir.mkdir("basetemp")
|
2008-08-16 23:26:59 +08:00
|
|
|
def spawn(cmd):
|
2009-03-17 21:10:17 +08:00
|
|
|
cmd = cmd + " --basetemp=" + str(basetemp)
|
2009-02-27 18:18:27 +08:00
|
|
|
return pexpect.spawn(cmd, logfile=tmpdir.join("spawn.out").open("w"))
|
2008-08-16 23:26:59 +08:00
|
|
|
return spawn
|
2008-09-10 05:40:21 +08:00
|
|
|
|
|
|
|
def requirespexpect(self, version_needed):
|
2009-03-18 20:05:18 +08:00
|
|
|
pexpect = py.test.importorskip("pexpect")
|
2008-09-10 05:40:21 +08:00
|
|
|
ver = tuple(map(int, pexpect.__version__.split(".")))
|
|
|
|
if ver < version_needed:
|
|
|
|
py.test.skip("pexpect version %s needed" %(".".join(map(str, version_needed))))
|
2008-08-16 23:26:59 +08:00
|
|
|
|
2009-02-27 18:18:27 +08:00
|
|
|
def test_pdb_interaction(self, testdir):
|
2008-09-10 05:40:21 +08:00
|
|
|
self.requirespexpect((2,3))
|
2009-02-27 18:18:27 +08:00
|
|
|
spawn = self.getspawn(testdir.tmpdir)
|
|
|
|
p1 = testdir.makepyfile("""
|
2008-08-16 23:26:59 +08:00
|
|
|
def test_1():
|
2009-02-27 18:18:27 +08:00
|
|
|
i = 0
|
|
|
|
assert i == 1
|
2008-08-16 23:26:59 +08:00
|
|
|
""")
|
2009-02-27 18:18:27 +08:00
|
|
|
child = spawn("%s %s --pdb %s" % (py.std.sys.executable, pytestpath, p1))
|
2008-09-10 02:18:22 +08:00
|
|
|
child.timeout = EXPECTTIMEOUT
|
2009-02-27 18:18:27 +08:00
|
|
|
#child.expect(".*def test_1.*")
|
|
|
|
child.expect(".*i = 0.*")
|
2008-10-07 17:26:56 +08:00
|
|
|
child.expect("(Pdb)")
|
2008-08-16 23:26:59 +08:00
|
|
|
child.sendeof()
|
2009-02-27 18:18:27 +08:00
|
|
|
child.expect("1 failed")
|
2008-09-10 02:18:22 +08:00
|
|
|
if child.isalive():
|
|
|
|
child.wait()
|
2008-08-16 23:26:59 +08:00
|
|
|
|
2009-03-22 04:07:45 +08:00
|
|
|
def test_simple_looponfail_interaction(self, testdir):
|
2009-02-27 18:18:27 +08:00
|
|
|
spawn = self.getspawn(testdir.tmpdir)
|
|
|
|
p1 = testdir.makepyfile("""
|
2008-08-16 23:26:59 +08:00
|
|
|
def test_1():
|
|
|
|
assert 1 == 0
|
|
|
|
""")
|
2009-02-27 18:18:27 +08:00
|
|
|
p1.setmtime(p1.mtime() - 50.0)
|
2009-03-22 04:07:45 +08:00
|
|
|
child = spawn("%s %s --looponfail %s" % (py.std.sys.executable, pytestpath, p1))
|
2008-08-16 23:26:59 +08:00
|
|
|
child.timeout = EXPECTTIMEOUT
|
|
|
|
child.expect("assert 1 == 0")
|
2009-03-22 04:07:45 +08:00
|
|
|
child.expect("test_simple_looponfail_interaction.py:")
|
2009-02-27 18:18:27 +08:00
|
|
|
child.expect("1 failed")
|
2008-08-16 23:26:59 +08:00
|
|
|
child.expect("waiting for changes")
|
2009-02-27 18:18:27 +08:00
|
|
|
p1.write(py.code.Source("""
|
2008-08-16 23:26:59 +08:00
|
|
|
def test_1():
|
|
|
|
assert 1 == 1
|
|
|
|
"""))
|
2009-03-22 04:07:45 +08:00
|
|
|
child.expect("MODIFIED.*test_simple_looponfail_interaction.py", timeout=4.0)
|
2009-02-27 18:18:27 +08:00
|
|
|
child.expect("1 passed", timeout=5.0)
|
2008-08-16 23:26:59 +08:00
|
|
|
child.kill(15)
|
2009-03-23 01:41:36 +08:00
|
|
|
|
|
|
|
class TestKeyboardInterrupt:
|
|
|
|
def test_raised_in_testfunction(self, testdir):
|
|
|
|
p1 = testdir.makepyfile("""
|
|
|
|
import py
|
|
|
|
def test_fail():
|
|
|
|
raise ValueError()
|
|
|
|
def test_inter():
|
|
|
|
raise KeyboardInterrupt()
|
|
|
|
""")
|
|
|
|
result = testdir.runpytest(p1)
|
|
|
|
result.stdout.fnmatch_lines([
|
|
|
|
#"*test_inter() INTERRUPTED",
|
|
|
|
"*KEYBOARD INTERRUPT*",
|
|
|
|
"*1 failed*",
|
|
|
|
])
|
|
|
|
|