2008-08-16 23:26:59 +08:00
|
|
|
import py
|
|
|
|
|
|
|
|
EXPECTTIMEOUT=10.0
|
|
|
|
|
2009-03-23 01:41:36 +08:00
|
|
|
class TestGeneralUsage:
|
2009-08-14 22:16:40 +08:00
|
|
|
def test_version(self, testdir):
|
|
|
|
assert py.version == py.__version__
|
|
|
|
result = testdir.runpytest("--version")
|
|
|
|
assert result.ret == 0
|
|
|
|
p = py.path.local(py.__file__).dirpath()
|
|
|
|
assert result.stderr.fnmatch_lines([
|
|
|
|
'*py.test*%s*, imported from: %s*' % (py.version, p)
|
|
|
|
])
|
2009-03-17 15:03:49 +08:00
|
|
|
def test_config_error(self, testdir):
|
|
|
|
testdir.makeconftest("""
|
2009-05-19 05:26:16 +08:00
|
|
|
def pytest_configure(config):
|
|
|
|
raise config.Error("hello")
|
2009-03-17 15:03:49 +08:00
|
|
|
""")
|
|
|
|
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="""
|
2009-05-19 05:26:16 +08:00
|
|
|
def pytest_addoption(parser):
|
|
|
|
parser.addoption("--xyz", dest="xyz", action="store")
|
2009-04-18 02:09:29 +08:00
|
|
|
""")
|
|
|
|
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_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-08-06 21:26:45 +08:00
|
|
|
|
|
|
|
def test_not_collectable_arguments(self, testdir):
|
|
|
|
p1 = testdir.makepyfile("")
|
|
|
|
p2 = testdir.makefile(".pyc", "123")
|
|
|
|
result = testdir.runpytest(p1, p2)
|
|
|
|
assert result.ret != 0
|
|
|
|
assert result.stderr.fnmatch_lines([
|
|
|
|
"*ERROR: can't collect: %s" %(p2,)
|
|
|
|
])
|