Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Display empty or None help parameter for parser option as empty string #7427

Merged
merged 10 commits into from Jul 29, 2020
1 change: 1 addition & 0 deletions changelog/7394.bugfix.rst
@@ -0,0 +1 @@
Fixed an empty/None help param on parser options from throwing an unexpected error when executing ``pytest --help``.
hp310780 marked this conversation as resolved.
Show resolved Hide resolved
2 changes: 2 additions & 0 deletions src/_pytest/helpconfig.py
Expand Up @@ -170,6 +170,8 @@ def showhelp(config: Config) -> None:
help, type, default = config._parser._inidict[name]
if type is None:
type = "string"
if help in (None, ""):
hp310780 marked this conversation as resolved.
Show resolved Hide resolved
raise TypeError("help argument cannot be empty for {}".format(name))
spec = "{} ({}):".format(name, type)
tw.write(" %s" % spec)
spec_len = len(spec)
Expand Down
24 changes: 24 additions & 0 deletions testing/test_helpconfig.py
Expand Up @@ -38,6 +38,30 @@ def test_help(testdir):
)


@pytest.mark.parametrize(
"conftest",
[
"""
def pytest_addoption(parser):
parser.addini("test_ini", "", default=True, type="bool")
""",
"""
def pytest_addoption(parser):
parser.addini("test_ini", None, default=True, type="bool")
""",
],
)
@pytest.mark.parametrize(
"output", ["*TypeError: help argument cannot be empty for test_ini*"]
)
def test_empty_or_none_help_param(conftest, output, testdir):
"""Tests an empty/None help param is displayed correctly.
"""
testdir.makeconftest(conftest)
result = testdir.runpytest("--help")
result.stderr.fnmatch_lines([output])


def test_hookvalidation_unknown(testdir):
testdir.makeconftest(
"""
Expand Down