-
-
Notifications
You must be signed in to change notification settings - Fork 2.7k
/
Copy pathtest_helpconfig.py
127 lines (104 loc) · 4.09 KB
/
test_helpconfig.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
# mypy: allow-untyped-defs
from __future__ import annotations
from _pytest.config import ExitCode
from _pytest.pytester import Pytester
import pytest
def test_version_verbose(pytester: Pytester, pytestconfig, monkeypatch) -> None:
monkeypatch.delenv("PYTEST_DISABLE_PLUGIN_AUTOLOAD")
result = pytester.runpytest("--version", "--version")
assert result.ret == 0
result.stdout.fnmatch_lines([f"*pytest*{pytest.__version__}*imported from*"])
if pytestconfig.pluginmanager.list_plugin_distinfo():
result.stdout.fnmatch_lines(["*registered third-party plugins:", "*at*"])
def test_version_less_verbose(pytester: Pytester, pytestconfig, monkeypatch) -> None:
monkeypatch.delenv("PYTEST_DISABLE_PLUGIN_AUTOLOAD")
result = pytester.runpytest("--version")
assert result.ret == 0
result.stdout.fnmatch_lines([f"pytest {pytest.__version__}"])
def test_versions():
"""Regression check for the public version attributes in pytest."""
assert isinstance(pytest.__version__, str)
assert isinstance(pytest.version_tuple, tuple)
def test_help(pytester: Pytester) -> None:
result = pytester.runpytest("--help")
assert result.ret == 0
result.stdout.fnmatch_lines(
"""
-m MARKEXPR Only run tests matching given mark expression. For
example: -m 'mark1 and not mark2'.
Reporting:
--durations=N *
-V, --version Display pytest version and information about plugins.
When given twice, also display information about
plugins.
*setup.cfg*
*minversion*
*to see*markers*pytest --markers*
*to see*fixtures*pytest --fixtures*
"""
)
def test_none_help_param_raises_exception(pytester: Pytester) -> None:
"""Test that a None help param raises a TypeError."""
pytester.makeconftest(
"""
def pytest_addoption(parser):
parser.addini("test_ini", None, default=True, type="bool")
"""
)
result = pytester.runpytest("--help")
result.stderr.fnmatch_lines(
["*TypeError: help argument cannot be None for test_ini*"]
)
def test_empty_help_param(pytester: Pytester) -> None:
"""Test that an empty help param is displayed correctly."""
pytester.makeconftest(
"""
def pytest_addoption(parser):
parser.addini("test_ini", "", default=True, type="bool")
"""
)
result = pytester.runpytest("--help")
assert result.ret == 0
lines = [
" required_plugins (args):",
" Plugins that must be present for pytest to run*",
" test_ini (bool):*",
"Environment variables:",
]
result.stdout.fnmatch_lines(lines, consecutive=True)
def test_hookvalidation_unknown(pytester: Pytester) -> None:
pytester.makeconftest(
"""
def pytest_hello(xyz):
pass
"""
)
result = pytester.runpytest()
assert result.ret != 0
result.stdout.fnmatch_lines(["*unknown hook*pytest_hello*"])
def test_hookvalidation_optional(pytester: Pytester) -> None:
pytester.makeconftest(
"""
import pytest
@pytest.hookimpl(optionalhook=True)
def pytest_hello(xyz):
pass
"""
)
result = pytester.runpytest()
assert result.ret == ExitCode.NO_TESTS_COLLECTED
def test_traceconfig(pytester: Pytester) -> None:
result = pytester.runpytest("--traceconfig")
result.stdout.fnmatch_lines(["*using*pytest*", "*active plugins*"])
def test_debug(pytester: Pytester) -> None:
result = pytester.runpytest_subprocess("--debug")
assert result.ret == ExitCode.NO_TESTS_COLLECTED
p = pytester.path.joinpath("pytestdebug.log")
assert "pytest_sessionstart" in p.read_text("utf-8")
def test_PYTEST_DEBUG(pytester: Pytester, monkeypatch) -> None:
monkeypatch.setenv("PYTEST_DEBUG", "1")
result = pytester.runpytest_subprocess()
assert result.ret == ExitCode.NO_TESTS_COLLECTED
result.stderr.fnmatch_lines(
["*pytest_plugin_registered*", "*manager*PluginManager*"]
)