test_ok1/testing/test_helpconfig.py

78 lines
2.1 KiB
Python
Raw Normal View History

from __future__ import absolute_import
from __future__ import division
from __future__ import print_function
import pytest
from _pytest.main import EXIT_NOTESTSCOLLECTED
def test_version(testdir, pytestconfig):
result = testdir.runpytest("--version")
assert result.ret == 0
# 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__)]
)
if pytestconfig.pluginmanager.list_plugin_distinfo():
2018-05-23 22:48:46 +08:00
result.stderr.fnmatch_lines(["*setuptools registered plugins:", "*at*"])
def test_help(testdir):
result = testdir.runpytest("--help")
assert result.ret == 0
2018-05-23 22:48:46 +08:00
result.stdout.fnmatch_lines(
"""
*-v*verbose*
*setup.cfg*
*minversion*
*to see*markers*pytest --markers*
*to see*fixtures*pytest --fixtures*
2018-05-23 22:48:46 +08:00
"""
)
def test_hookvalidation_unknown(testdir):
2018-05-23 22:48:46 +08:00
testdir.makeconftest(
"""
def pytest_hello(xyz):
pass
2018-05-23 22:48:46 +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*"])
def test_hookvalidation_optional(testdir):
2018-05-23 22:48:46 +08:00
testdir.makeconftest(
"""
import pytest
@pytest.hookimpl(optionalhook=True)
def pytest_hello(xyz):
pass
2018-05-23 22:48:46 +08:00
"""
)
result = testdir.runpytest()
assert result.ret == EXIT_NOTESTSCOLLECTED
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*"])
def test_debug(testdir, monkeypatch):
result = testdir.runpytest_subprocess("--debug")
assert result.ret == EXIT_NOTESTSCOLLECTED
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_subprocess()
assert result.ret == EXIT_NOTESTSCOLLECTED
2018-05-23 22:48:46 +08:00
result.stderr.fnmatch_lines(
["*pytest_plugin_registered*", "*manager*PluginManager*"]
)