2009-12-29 23:29:48 +08:00
|
|
|
import sys, py
|
2008-08-16 23:26:59 +08:00
|
|
|
|
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("""
|
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
|
2010-01-14 01:04:58 +08:00
|
|
|
def test_option(pytestconfig):
|
|
|
|
assert pytestconfig.option.xyz == "123"
|
2009-04-18 02:09:29 +08:00
|
|
|
""")
|
|
|
|
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
|
2009-12-30 05:26:03 +08:00
|
|
|
def test_1(pytestconfig):
|
|
|
|
pytestconfig.getbasetemp().ensure("hello")
|
2009-03-17 18:29:45 +08:00
|
|
|
""")
|
|
|
|
result = testdir.runpytest(p, '--basetemp=%s' %mytemp)
|
|
|
|
assert result.ret == 0
|
2009-12-30 05:26:03 +08:00
|
|
|
assert mytemp.join('hello').check()
|
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([
|
2010-01-03 21:19:31 +08:00
|
|
|
#XXX on jython this fails: "> import import_fails",
|
2008-08-16 23:26:59 +08:00
|
|
|
"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,)
|
|
|
|
])
|
2009-12-29 23:29:48 +08:00
|
|
|
|
|
|
|
|
|
|
|
def test_earlyinit(self, testdir):
|
|
|
|
p = testdir.makepyfile("""
|
|
|
|
import py
|
|
|
|
assert hasattr(py.test, 'mark')
|
|
|
|
""")
|
2010-01-11 03:45:37 +08:00
|
|
|
result = testdir.runpython(p)
|
2009-12-29 23:29:48 +08:00
|
|
|
assert result.ret == 0
|
|
|
|
|
|
|
|
def test_pydoc(self, testdir):
|
2010-01-11 03:45:37 +08:00
|
|
|
result = testdir.runpython_c("import py ; help(py.test)")
|
2009-12-29 23:29:48 +08:00
|
|
|
assert result.ret == 0
|
|
|
|
s = result.stdout.str()
|
|
|
|
assert 'MarkGenerator' in s
|