Skip to content

Don't throw index error when running pytest --help when adding ini option via parser.addini in conftest.py with no help #7394

Closed
blueyed/pytest
#459
@gnikonorov

Description

@gnikonorov

a detailed description of the bug or suggestion

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

output of pip list from the virtual environment you are using

pip_list_pytest_help_issue.txt

pytest and operating system versions

Pytest is built from master locally:

(.venv) gnikonorov:~/pytest/gleb_test$ pytest --version
pytest 5.4.1.dev546+g4cc4ebf3c
(.venv) gnikonorov:~/pytest/gleb_test$

minimal example if possible

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$

Metadata

Metadata

Assignees

No one assigned

    Labels

    type: bugproblem that needs to be addressed

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions