When running pytest --help with a conftest.py file present that defines an ini option with an empty string as help text, an index error is thrown. We should not throw an error here, but what exactly we should do I think is open for discussion.
When passing None, a different error is throw. We should fix both the issue that happens with None and the empty string as part of this
pip list from the virtual environment you are usingpip_list_pytest_help_issue.txt
Pytest is built from master locally:
(.venv) gnikonorov:~/pytest/gleb_test$ pytest --version
pytest 5.4.1.dev546+g4cc4ebf3c
(.venv) gnikonorov:~/pytest/gleb_test$
Contents of conftest.py:
(.venv) gnikonorov:~/pytest/gleb_test$ cat conftest.py
def pytest_addoption(parser):
parser.addini("my_ini", "", default=True, type="bool")
(.venv) gnikonorov:~/pytest/gleb_test$
(.venv) gnikonorov:~/pytest/gleb_test$ pytest --help
usage: pytest [options] [file_or_dir] [file_or_dir] [...]
.....
Automatically find and add a Django project to the Python path.
FAIL_INVALID_TEMPLATE_VARS (bool):
Fail for invalid variables in templates.
my_ini (bool): Traceback (most recent call last):
File "/home/gnikonorov/pytest/.venv/bin/pytest", line 11, in <module>
load_entry_point('pytest', 'console_scripts', 'pytest')()
File "/home/gnikonorov/pytest/src/_pytest/config/__init__.py", line 165, in console_main
code = main()
File "/home/gnikonorov/pytest/src/_pytest/config/__init__.py", line 143, in main
config=config
File "/home/gnikonorov/pytest/.venv/lib/python3.6/site-packages/pluggy/hooks.py", line 286, in __call__
return self._hookexec(self, self.get_hookimpls(), kwargs)
File "/home/gnikonorov/pytest/.venv/lib/python3.6/site-packages/pluggy/manager.py", line 93, in _hookexec
return self._inner_hookexec(hook, methods, kwargs)
File "/home/gnikonorov/pytest/.venv/lib/python3.6/site-packages/pluggy/manager.py", line 87, in <lambda>
firstresult=hook.spec.opts.get("firstresult") if hook.spec else False,
File "/home/gnikonorov/pytest/.venv/lib/python3.6/site-packages/pluggy/callers.py", line 208, in _multicall
return outcome.get_result()
File "/home/gnikonorov/pytest/.venv/lib/python3.6/site-packages/pluggy/callers.py", line 80, in get_result
raise ex[1].with_traceback(ex[2])
File "/home/gnikonorov/pytest/.venv/lib/python3.6/site-packages/pluggy/callers.py", line 187, in _multicall
res = hook_impl.function(*args)
File "/home/gnikonorov/pytest/src/_pytest/helpconfig.py", line 148, in pytest_cmdline_main
showhelp(config)
File "/home/gnikonorov/pytest/src/_pytest/helpconfig.py", line 194, in showhelp
tw.line(wrapped[0])
IndexError: list index out of range
(.venv) gnikonorov:~/pytest/gleb_test$
I have tried this on a new virtualenv, on my Mac with the same commit hash. I couldn't repro the bug. Your pip seems too old.
What am I missing here?
@srinivasreddy, the issue actually has nothing to do with the commit. I didn't realize I had a conftest.py that added an ini option with no help text in my directory. Feel free to submit a PR for this if you'd like. I think we definitely should not throw here.
Hi, I thought I'd take a stab at resolving this bug and have submitted a PR that would resolve a None help parameter to an empty string and then fixed showhelp to work with an empty string (so both help="" and help=None should work). Let me know your feedback (and also if I've followed the guidelines correctly). Cheers.
Most helpful comment
Hi, I thought I'd take a stab at resolving this bug and have submitted a PR that would resolve a
Nonehelp parameter to an empty string and then fixedshowhelpto work with an empty string (so bothhelp=""andhelp=Noneshould work). Let me know your feedback (and also if I've followed the guidelines correctly). Cheers.