[BUG] reconfiguring rich via pytest at runtime
See original GitHub issueDescribe the bug
Trying to reconfigure rich when my code is run via pytest, using the following pytest hook:
# conftest.py
def pytest_configure():
try:
import rich
except ImportError:
pass
else:
rich.reconfigure(soft_wrap=False)
and invoking my tests with
pytest
I got the following error:
INTERNALERROR> Traceback (most recent call last):
INTERNALERROR> File "/Users/robcleme/.pyenv/versions/wxc-dev/lib/python3.9/site-packages/_pytest/main.py", line 265, in wrap_session
INTERNALERROR> config._do_configure()
INTERNALERROR> File "/Users/robcleme/.pyenv/versions/wxc-dev/lib/python3.9/site-packages/_pytest/config/__init__.py", line 982, in _do_configure
INTERNALERROR> self.hook.pytest_configure.call_historic(kwargs=dict(config=self))
INTERNALERROR> File "/Users/robcleme/.pyenv/versions/wxc-dev/lib/python3.9/site-packages/pluggy/hooks.py", line 308, in call_historic
INTERNALERROR> res = self._hookexec(self, self.get_hookimpls(), kwargs)
INTERNALERROR> File "/Users/robcleme/.pyenv/versions/wxc-dev/lib/python3.9/site-packages/pluggy/manager.py", line 93, in _hookexec
INTERNALERROR> return self._inner_hookexec(hook, methods, kwargs)
INTERNALERROR> File "/Users/robcleme/.pyenv/versions/wxc-dev/lib/python3.9/site-packages/pluggy/manager.py", line 84, in <lambda>
INTERNALERROR> self._inner_hookexec = lambda hook, methods, kwargs: hook.multicall(
INTERNALERROR> File "/Users/robcleme/.pyenv/versions/wxc-dev/lib/python3.9/site-packages/pluggy/callers.py", line 208, in _multicall
INTERNALERROR> return outcome.get_result()
INTERNALERROR> File "/Users/robcleme/.pyenv/versions/wxc-dev/lib/python3.9/site-packages/pluggy/callers.py", line 80, in get_result
INTERNALERROR> raise ex[1].with_traceback(ex[2])
INTERNALERROR> File "/Users/robcleme/.pyenv/versions/wxc-dev/lib/python3.9/site-packages/pluggy/callers.py", line 187, in _multicall
INTERNALERROR> res = hook_impl.function(*args)
INTERNALERROR> File "/Users/robcleme/dev/my/wxc/tests/conftest.py", line 33, in pytest_configure
INTERNALERROR> rich.reconfigure(soft_wrap=False)
INTERNALERROR> File "/Users/robcleme/.pyenv/versions/wxc-dev/lib/python3.9/site-packages/rich/__init__.py", line 45, in reconfigure
INTERNALERROR> _console.__dict__ = new_console.__dict__
INTERNALERROR> AttributeError: 'NoneType' object has no attribute '__dict__'
Platform OsX
Diagnose
python -m rich.diagnose
python -m rich._windows
pip freeze | grep rich
โญโโโโโโโโโโโโโโโโโโโโโโโโโ <class 'rich.console.Console'> โโโโโโโโโโโโโโโโโโโโโโโโโโฎ
โ A high level console interface. โ
โ โ
โ โญโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโฎ โ
โ โ <console width=185 ColorSystem.TRUECOLOR> โ โ
โ โฐโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโฏ โ
โ โ
โ color_system = 'truecolor' โ
โ encoding = 'utf-8' โ
โ file = <_io.TextIOWrapper name='<stdout>' mode='w' encoding='utf-8'> โ
โ height = 52 โ
โ is_alt_screen = False โ
โ is_dumb_terminal = False โ
โ is_interactive = True โ
โ is_jupyter = False โ
โ is_terminal = True โ
โ legacy_windows = False โ
โ no_color = False โ
โ options = ConsoleOptions( โ
โ size=ConsoleDimensions(width=185, height=52), โ
โ legacy_windows=False, โ
โ min_width=1, โ
โ max_width=185, โ
โ is_terminal=True, โ
โ encoding='utf-8', โ
โ max_height=52, โ
โ justify=None, โ
โ overflow=None, โ
โ no_wrap=False, โ
โ highlight=None, โ
โ markup=None, โ
โ height=None โ
โ ) โ
โ quiet = False โ
โ record = False โ
โ safe_box = True โ
โ size = ConsoleDimensions(width=185, height=52) โ
โ soft_wrap = False โ
โ stderr = False โ
โ style = None โ
โ tab_size = 8 โ
โ width = 185 โ
โฐโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโฏ
platform="Darwin"
WindowsConsoleFeatures(vt=False, truecolor=False)
rich==10.7.0
Issue Analytics
- State:
- Created 2 years ago
- Comments:8 (4 by maintainers)
Top Results From Across the Web
[BUG] Rich is incompatible with pytest capsys fixture #317
I'm having the same issue, I used click.echo and it worked, but now I tried using rich and when I'm looking at the:...
Read more >pytest Documentation - Read the Docs
You can check that code raises a particular warning using pytest.warns. 2.2.4 Making use of context-sensitive comparisons pytest has rich ...
Read more >Plugin List โ pytest documentation
name summary last release status requi...
pytestโaccept A pytestโplugin for updating doctest outputs Jan 07, 2022 N/A pytes...
pytestโaddonsโtest ็จไบๆต่ฏpytest็ๆไปถ Aug 02, 2021 N/A pytes...
pytestโaio...
Read more >API Reference โ pytest documentation
The approx class performs floating-point comparisons using a syntax ... This is because the call hierarchy of rich comparisons follows a fixed behavior....
Read more >Changelog โ pytest documentation
The plan is to make returning non- None from tests an error in the future. ... This is not currently enforced at runtime,...
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Ah, seems so. I can make my problem go away by setting that in my pytest hook. Good call !
Sure. Right now Iโm trying to live up to the spirit of my tweet https://twitter.com/neutrinoceros/status/1428812031524810756?s=20 This specific project is extremely small so Iโd like to keep the technical debt close to zero, so Iโll avoid using rich to the fullest for now ๐
Well the output is really what I need to check, and rich is only an optional dependency at this point. But Iโll keep this in mind for other projects where Iโm integrating rich. Thanks !
while a possible patch on the rich side is proposed in #1426, a workaround this issue for existing versions of rich is to simply modify the pytest hook as: