2018-10-25 15:01:29 +08:00
|
|
|
from __future__ import absolute_import
|
|
|
|
from __future__ import division
|
|
|
|
from __future__ import print_function
|
|
|
|
|
2014-10-02 21:25:42 +08:00
|
|
|
import pytest
|
2018-10-25 15:01:29 +08:00
|
|
|
from _pytest.main import EXIT_NOTESTSCOLLECTED
|
2009-08-19 21:45:01 +08:00
|
|
|
|
2017-07-17 07:25:09 +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
|
2017-07-17 07:25:09 +08:00
|
|
|
# p = py.path.local(py.__file__).dirpath()
|
2018-08-23 09:30:42 +08:00
|
|
|
result.stderr.fnmatch_lines(
|
|
|
|
["*pytest*{}*imported from*".format(pytest.__version__)]
|
|
|
|
)
|
2015-05-06 03:53:04 +08:00
|
|
|
if pytestconfig.pluginmanager.list_plugin_distinfo():
|
2018-05-23 22:48:46 +08:00
|
|
|
result.stderr.fnmatch_lines(["*setuptools registered plugins:", "*at*"])
|
2009-08-19 21:45:01 +08:00
|
|
|
|
2017-07-17 07:25:09 +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
|
2018-05-23 22:48:46 +08:00
|
|
|
result.stdout.fnmatch_lines(
|
|
|
|
"""
|
2012-09-22 17:44:56 +08:00
|
|
|
*-v*verbose*
|
|
|
|
*setup.cfg*
|
|
|
|
*minversion*
|
2016-06-21 22:16:57 +08:00
|
|
|
*to see*markers*pytest --markers*
|
|
|
|
*to see*fixtures*pytest --fixtures*
|
2018-05-23 22:48:46 +08:00
|
|
|
"""
|
|
|
|
)
|
2009-08-19 21:45:01 +08:00
|
|
|
|
2017-07-17 07:25:09 +08:00
|
|
|
|
2010-04-22 17:57:57 +08:00
|
|
|
def test_hookvalidation_unknown(testdir):
|
2018-05-23 22:48:46 +08:00
|
|
|
testdir.makeconftest(
|
|
|
|
"""
|
2010-04-22 17:57:57 +08:00
|
|
|
def pytest_hello(xyz):
|
|
|
|
pass
|
2018-05-23 22:48:46 +08:00
|
|
|
"""
|
|
|
|
)
|
2010-04-22 17:57:57 +08:00
|
|
|
result = testdir.runpytest()
|
|
|
|
assert result.ret != 0
|
2018-05-23 22:48:46 +08:00
|
|
|
result.stdout.fnmatch_lines(["*unknown hook*pytest_hello*"])
|
2010-04-22 17:57:57 +08:00
|
|
|
|
2017-07-17 07:25:09 +08:00
|
|
|
|
2010-04-22 17:57:57 +08:00
|
|
|
def test_hookvalidation_optional(testdir):
|
2018-05-23 22:48:46 +08:00
|
|
|
testdir.makeconftest(
|
|
|
|
"""
|
2010-11-18 05:12:16 +08:00
|
|
|
import pytest
|
2015-05-06 16:08:08 +08:00
|
|
|
@pytest.hookimpl(optionalhook=True)
|
2010-04-22 17:57:57 +08:00
|
|
|
def pytest_hello(xyz):
|
|
|
|
pass
|
2018-05-23 22:48:46 +08:00
|
|
|
"""
|
|
|
|
)
|
2010-04-22 17:57:57 +08:00
|
|
|
result = testdir.runpytest()
|
2015-07-05 01:42:22 +08:00
|
|
|
assert result.ret == EXIT_NOTESTSCOLLECTED
|
2010-04-22 17:57:57 +08:00
|
|
|
|
2017-07-17 07:25:09 +08:00
|
|
|
|
2011-01-13 02:39:36 +08:00
|
|
|
def test_traceconfig(testdir):
|
|
|
|
result = testdir.runpytest("--traceconfig")
|
2018-05-23 22:48:46 +08:00
|
|
|
result.stdout.fnmatch_lines(["*using*pytest*py*", "*active plugins*"])
|
2011-07-15 01:11:50 +08:00
|
|
|
|
2017-07-17 07:25:09 +08:00
|
|
|
|
2011-07-15 01:11:50 +08:00
|
|
|
def test_debug(testdir, monkeypatch):
|
2015-04-28 17:54:46 +08:00
|
|
|
result = testdir.runpytest_subprocess("--debug")
|
2015-07-05 01:42:22 +08:00
|
|
|
assert result.ret == EXIT_NOTESTSCOLLECTED
|
2011-07-15 01:11:50 +08:00
|
|
|
p = testdir.tmpdir.join("pytestdebug.log")
|
|
|
|
assert "pytest_sessionstart" in p.read()
|
|
|
|
|
2017-07-17 07:25:09 +08:00
|
|
|
|
2011-07-15 01:11:50 +08:00
|
|
|
def test_PYTEST_DEBUG(testdir, monkeypatch):
|
|
|
|
monkeypatch.setenv("PYTEST_DEBUG", "1")
|
2015-04-28 17:54:46 +08:00
|
|
|
result = testdir.runpytest_subprocess()
|
2015-07-05 01:42:22 +08:00
|
|
|
assert result.ret == EXIT_NOTESTSCOLLECTED
|
2018-05-23 22:48:46 +08:00
|
|
|
result.stderr.fnmatch_lines(
|
|
|
|
["*pytest_plugin_registered*", "*manager*PluginManager*"]
|
|
|
|
)
|