Skip to content

Make errors more friendly (INTERNALERROR>) #2293

@nicoddemus

Description

@nicoddemus

In general, users end up seeing a lot of INTERNALERROR> messages which are not really internal errors, but are uncaught exceptions which are not treated correctly.

For example, if a user mistypes a hook name in a conftest.py file (for example, pytest_confiure), here's what is displayed:

INTERNALERROR> Traceback (most recent call last):
INTERNALERROR>   File "C:\pytest\_pytest\main.py", line 98, in wrap_session
INTERNALERROR>     session.exitstatus = doit(config, session) or 0
INTERNALERROR>   File "C:\pytest\_pytest\main.py", line 132, in _main
INTERNALERROR>     config.hook.pytest_collection(session=session)
INTERNALERROR>   File "C:\pytest\_pytest\vendored_packages\pluggy.py", line 745, in __call__
INTERNALERROR>     return self._hookexec(self, self._nonwrappers + self._wrappers, kwargs)
INTERNALERROR>   File "C:\pytest\_pytest\vendored_packages\pluggy.py", line 339, in _hookexec
INTERNALERROR>     return self._inner_hookexec(hook, methods, kwargs)
INTERNALERROR>   File "C:\pytest\_pytest\vendored_packages\pluggy.py", line 302, in __call__
INTERNALERROR>     return outcome.get_result()
INTERNALERROR>   File "C:\pytest\_pytest\vendored_packages\pluggy.py", line 279, in get_result
INTERNALERROR>     raise ex[1].with_traceback(ex[2])
INTERNALERROR>   File "C:\pytest\_pytest\vendored_packages\pluggy.py", line 265, in __init__
INTERNALERROR>     self.result = func()
INTERNALERROR>   File "C:\pytest\_pytest\vendored_packages\pluggy.py", line 300, in <lambda>
INTERNALERROR>     outcome = _CallOutcome(lambda: self.oldcall(hook, hook_impls, kwargs))
INTERNALERROR>   File "C:\pytest\_pytest\vendored_packages\pluggy.py", line 334, in <lambda>
INTERNALERROR>     _MultiCall(methods, kwargs, hook.spec_opts).execute()
INTERNALERROR>   File "C:\pytest\_pytest\vendored_packages\pluggy.py", line 614, in execute
INTERNALERROR>     res = hook_impl.function(*args)
INTERNALERROR>   File "C:\pytest\_pytest\main.py", line 141, in pytest_collection
INTERNALERROR>     return session.perform_collect()
INTERNALERROR>   File "C:\pytest\_pytest\main.py", line 597, in perform_collect
INTERNALERROR>     self.config.pluginmanager.check_pending()
INTERNALERROR>   File "C:\pytest\_pytest\vendored_packages\pluggy.py", line 498, in check_pending
INTERNALERROR>     (name, hookimpl.plugin))
INTERNALERROR> _pytest.vendored_packages.pluggy.PluginValidationError: unknown hook 'pytest_confiure' in plugin <module 'conftest' (<_pytest.assertion.rewrite.AssertionRewritingHook object at 0x03911090>)>

======================== no tests ran in 0.01 seconds =========================

Fixture, collection, etc all have their own exception classes that are treated specially and displayed nicely (which is good), but I feel we should have more general classes that can be raised from anywhere in the code and would signal pytest that something is wrong and display a nice message. Perhaps UsageError is supposed to be it and just needs some polish?

Would like to brainstorm some ideas. I would like to improve things for 3.1 if possible.

Metadata

Metadata

Assignees

No one assigned

    Labels

    topic: reportingrelated to terminal output and user-facing messages and errorstype: enhancementnew feature or API change, should be merged into features branch

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions