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

Fix the "Customizing Colors" documentation section #11596

Closed
nicoddemus opened this issue Nov 7, 2023 Discussed in #11573 · 4 comments
Closed

Fix the "Customizing Colors" documentation section #11596

nicoddemus opened this issue Nov 7, 2023 Discussed in #11573 · 4 comments
Labels
good first issue easy issue that is friendly to new contributor type: docs documentation improvement, missing or needing clarification

Comments

@nicoddemus
Copy link
Member

Discussed in #11573

The section https://docs.pytest.org/en/7.4.x/how-to/logging.html#customizing-colors has a broken example. The "broken" means that it can no be copy/pasted to try and there are no explanations about how to use it.

@pytest.hookimpl
def pytest_configure(config):
    logging_plugin = config.pluginmanager.get_plugin("logging-plugin")

    # Change color on existing log level
    logging_plugin.log_cli_handler.formatter.add_color_level(logging.INFO, "cyan")

    # Add color to a custom log level (a custom log level `SPAM` is already set up)
    logging_plugin.log_cli_handler.formatter.add_color_level(logging.SPAM, "blue")
INTERNALERROR> Traceback (most recent call last):
INTERNALERROR>   File "/opt/pysetup/.venv/lib/python3.11/site-packages/_pytest/main.py", line 267, in wrap_session
INTERNALERROR>     config._do_configure()
INTERNALERROR>   File "/opt/pysetup/.venv/lib/python3.11/site-packages/_pytest/config/__init__.py", line 1053, in _do_configure
INTERNALERROR>     self.hook.pytest_configure.call_historic(kwargs=dict(config=self))
INTERNALERROR>   File "/opt/pysetup/.venv/lib/python3.11/site-packages/pluggy/_hooks.py", line 514, in call_historic
INTERNALERROR>     res = self._hookexec(self.name, self._hookimpls, kwargs, False)
INTERNALERROR>           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
INTERNALERROR>   File "/opt/pysetup/.venv/lib/python3.11/site-packages/pluggy/_manager.py", line 115, in _hookexec
INTERNALERROR>     return self._inner_hookexec(hook_name, methods, kwargs, firstresult)
INTERNALERROR>            ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
INTERNALERROR>   File "/opt/pysetup/.venv/lib/python3.11/site-packages/pluggy/_callers.py", line 113, in _multicall
INTERNALERROR>     raise exception.with_traceback(exception.__traceback__)
INTERNALERROR>   File "/opt/pysetup/.venv/lib/python3.11/site-packages/pluggy/_callers.py", line 77, in _multicall
INTERNALERROR>     res = hook_impl.function(*args)
INTERNALERROR>           ^^^^^^^^^^^^^^^^^^^^^^^^^
INTERNALERROR>   File "/opt/pysetup/tests/conftest.py", line 49, in pytest_configure
INTERNALERROR>     logging_plugin.log_cli_handler.formatter.add_color_level(logging.INFO, "cyan")
INTERNALERROR>     ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
INTERNALERROR> AttributeError: 'NoneType' object has no attribute 'log_cli_handler'

Expected

Add a small working code example or clarify instructions.

@nicoddemus nicoddemus added type: docs documentation improvement, missing or needing clarification good first issue easy issue that is friendly to new contributor labels Nov 7, 2023
@nicoddemus
Copy link
Member Author

I think the example can be fixed simply by using config.pluginmanager.get_plugin("logging").

@aarushis18
Copy link

Hi! Is it okay if I work on this? I should be able to submit a PR within the next week.

@nicoddemus
Copy link
Member Author

nicoddemus commented Nov 8, 2023

@aarushis18 sure!

Please also make sure the updated example works.

Also in the future feel free to go ahead and open PRs for unassigned issues like this, no need to ask permission. 👍

@touilleWoman
Copy link
Contributor

Hello, this issue can be closed. Problem solved with PR #11652.
Sorry I mentioned the wrong issue in my PR, I wrote " close #11573" instead of "close #11596".

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
good first issue easy issue that is friendly to new contributor type: docs documentation improvement, missing or needing clarification
Projects
None yet
Development

No branches or pull requests

4 participants