2013-10-12 21:39:22 +08:00
|
|
|
import py, pytest
|
2014-10-01 18:20:11 +08:00
|
|
|
from _pytest.core import collectattr
|
2009-08-19 21:45:01 +08:00
|
|
|
|
2011-01-13 02:39:36 +08:00
|
|
|
def test_version(testdir, pytestconfig):
|
2009-08-19 21:45:01 +08:00
|
|
|
result = testdir.runpytest("--version")
|
|
|
|
assert result.ret == 0
|
2009-12-31 01:11:00 +08:00
|
|
|
#p = py.path.local(py.__file__).dirpath()
|
2010-04-29 06:12:38 +08:00
|
|
|
result.stderr.fnmatch_lines([
|
2014-01-18 19:31:33 +08:00
|
|
|
'*pytest*%s*imported from*' % (pytest.__version__, )
|
2009-08-19 21:45:01 +08:00
|
|
|
])
|
2011-01-13 02:39:36 +08:00
|
|
|
if pytestconfig.pluginmanager._plugin_distinfo:
|
|
|
|
result.stderr.fnmatch_lines([
|
|
|
|
"*setuptools registered plugins:",
|
|
|
|
"*at*",
|
|
|
|
])
|
2009-08-19 21:45:01 +08:00
|
|
|
|
2010-10-28 04:29:01 +08:00
|
|
|
def test_help(testdir):
|
|
|
|
result = testdir.runpytest("--help")
|
2009-08-19 21:45:01 +08:00
|
|
|
assert result.ret == 0
|
2012-09-22 17:44:56 +08:00
|
|
|
result.stdout.fnmatch_lines("""
|
|
|
|
*-v*verbose*
|
|
|
|
*setup.cfg*
|
|
|
|
*minversion*
|
|
|
|
*to see*markers*py.test --markers*
|
2012-10-05 20:24:44 +08:00
|
|
|
*to see*fixtures*py.test --fixtures*
|
2012-09-22 17:44:56 +08:00
|
|
|
""")
|
2009-08-19 21:45:01 +08:00
|
|
|
|
2009-12-29 17:59:01 +08:00
|
|
|
def test_collectattr():
|
|
|
|
class A:
|
|
|
|
def pytest_hello(self):
|
|
|
|
pass
|
|
|
|
class B(A):
|
|
|
|
def pytest_world(self):
|
|
|
|
pass
|
|
|
|
methods = py.builtin.sorted(collectattr(B))
|
|
|
|
assert list(methods) == ['pytest_hello', 'pytest_world']
|
|
|
|
methods = py.builtin.sorted(collectattr(B()))
|
|
|
|
assert list(methods) == ['pytest_hello', 'pytest_world']
|
|
|
|
|
2010-04-22 17:57:57 +08:00
|
|
|
def test_hookvalidation_unknown(testdir):
|
|
|
|
testdir.makeconftest("""
|
|
|
|
def pytest_hello(xyz):
|
|
|
|
pass
|
|
|
|
""")
|
|
|
|
result = testdir.runpytest()
|
|
|
|
assert result.ret != 0
|
2010-04-29 06:12:38 +08:00
|
|
|
result.stderr.fnmatch_lines([
|
2010-04-22 17:57:57 +08:00
|
|
|
'*unknown hook*pytest_hello*'
|
|
|
|
])
|
|
|
|
|
|
|
|
def test_hookvalidation_optional(testdir):
|
|
|
|
testdir.makeconftest("""
|
2010-11-18 05:12:16 +08:00
|
|
|
import pytest
|
|
|
|
@pytest.mark.optionalhook
|
2010-04-22 17:57:57 +08:00
|
|
|
def pytest_hello(xyz):
|
|
|
|
pass
|
|
|
|
""")
|
|
|
|
result = testdir.runpytest()
|
|
|
|
assert result.ret == 0
|
|
|
|
|
2011-01-13 02:39:36 +08:00
|
|
|
def test_traceconfig(testdir):
|
|
|
|
result = testdir.runpytest("--traceconfig")
|
|
|
|
result.stdout.fnmatch_lines([
|
|
|
|
"*using*pytest*py*",
|
|
|
|
"*active plugins*",
|
|
|
|
])
|
2011-07-15 01:11:50 +08:00
|
|
|
|
|
|
|
def test_debug(testdir, monkeypatch):
|
|
|
|
result = testdir.runpytest("--debug")
|
|
|
|
assert result.ret == 0
|
|
|
|
p = testdir.tmpdir.join("pytestdebug.log")
|
|
|
|
assert "pytest_sessionstart" in p.read()
|
|
|
|
|
|
|
|
def test_PYTEST_DEBUG(testdir, monkeypatch):
|
|
|
|
monkeypatch.setenv("PYTEST_DEBUG", "1")
|
|
|
|
result = testdir.runpytest()
|
|
|
|
assert result.ret == 0
|
|
|
|
result.stderr.fnmatch_lines([
|
2012-12-05 03:31:37 +08:00
|
|
|
"*pytest_plugin_registered*",
|
|
|
|
"*manager*PluginManager*"
|
2011-07-15 01:11:50 +08:00
|
|
|
])
|