Accommodate console lines that don't match standard sections
Encountered a very highly customized version of Pytest which munges the console output to send lines before the famous === test session starts === line. This caused an exception:
Traceback (most recent call last):
File "/Users/jwr003/repos/gems-qa-auto/venv/bin/gems-qa-tests", line 33, in <module>
sys.exit(load_entry_point('gems-qa-auto', 'console_scripts', 'gems-qa-tests')())
File "/Users/jwr003/repos/gems-qa-auto/gems_qa_tests/__main__.py", line 11, in main
pytest.main()
File "/Users/jwr003/repos/gems-qa-auto/venv/lib/python3.9/site-packages/_pytest/config/__init__.py", line 162, in main
ret: Union[ExitCode, int] = config.hook.pytest_cmdline_main(
File "/Users/jwr003/repos/gems-qa-auto/venv/lib/python3.9/site-packages/pluggy/hooks.py", line 286, in __call__
return self._hookexec(self, self.get_hookimpls(), kwargs)
File "/Users/jwr003/repos/gems-qa-auto/venv/lib/python3.9/site-packages/pluggy/manager.py", line 93, in _hookexec
return self._inner_hookexec(hook, methods, kwargs)
File "/Users/jwr003/repos/gems-qa-auto/venv/lib/python3.9/site-packages/pluggy/manager.py", line 84, in <lambda>
self._inner_hookexec = lambda hook, methods, kwargs: hook.multicall(
File "/Users/jwr003/repos/gems-qa-auto/venv/lib/python3.9/site-packages/pluggy/callers.py", line 208, in _multicall
return outcome.get_result()
File "/Users/jwr003/repos/gems-qa-auto/venv/lib/python3.9/site-packages/pluggy/callers.py", line 80, in get_result
raise ex[1].with_traceback(ex[2])
File "/Users/jwr003/repos/gems-qa-auto/venv/lib/python3.9/site-packages/pluggy/callers.py", line 187, in _multicall
res = hook_impl.function(*args)
File "/Users/jwr003/repos/gems-qa-auto/venv/lib/python3.9/site-packages/_pytest/main.py", line 316, in pytest_cmdline_main
return wrap_session(config, _main)
File "/Users/jwr003/repos/gems-qa-auto/venv/lib/python3.9/site-packages/_pytest/main.py", line 289, in wrap_session
config.notify_exception(excinfo, config.option)
File "/Users/jwr003/repos/gems-qa-auto/venv/lib/python3.9/site-packages/_pytest/config/__init__.py", line 1037, in notify_exception
res = self.hook.pytest_internalerror(excrepr=excrepr, excinfo=excinfo)
File "/Users/jwr003/repos/gems-qa-auto/venv/lib/python3.9/site-packages/pluggy/hooks.py", line 286, in __call__
return self._hookexec(self, self.get_hookimpls(), kwargs)
File "/Users/jwr003/repos/gems-qa-auto/venv/lib/python3.9/site-packages/pluggy/manager.py", line 93, in _hookexec
return self._inner_hookexec(hook, methods, kwargs)
File "/Users/jwr003/repos/gems-qa-auto/venv/lib/python3.9/site-packages/pluggy/manager.py", line 84, in <lambda>
self._inner_hookexec = lambda hook, methods, kwargs: hook.multicall(
File "/Users/jwr003/repos/gems-qa-auto/venv/lib/python3.9/site-packages/pluggy/callers.py", line 208, in _multicall
return outcome.get_result()
File "/Users/jwr003/repos/gems-qa-auto/venv/lib/python3.9/site-packages/pluggy/callers.py", line 80, in get_result
raise ex[1].with_traceback(ex[2])
File "/Users/jwr003/repos/gems-qa-auto/venv/lib/python3.9/site-packages/pluggy/callers.py", line 187, in _multicall
res = hook_impl.function(*args)
File "/Users/jwr003/repos/gems-qa-auto/venv/lib/python3.9/site-packages/_pytest/terminal.py", line 474, in pytest_internalerror
self.write_line("INTERNALERROR> " + line)
File "/Users/jwr003/repos/gems-qa-auto/venv/lib/python3.9/site-packages/_pytest/terminal.py", line 430, in write_line
self._tw.line(line, **markup)
File "/Users/jwr003/repos/gems-qa-auto/venv/lib/python3.9/site-packages/_pytest/_io/terminalwriter.py", line 170, in line
self.write(s, **markup)
File "/Users/jwr003/repos/gems-qa-auto/venv/lib/python3.9/site-packages/pytest_tui/plugin.py", line 150, in tee_write
if not config._tui_current_section:
AttributeError: 'Config' object has no attribute '_tui_current_section'
What needs to happen is we need to assign a new output section (likee "other") to act as a catch-all for lines coming in that are not part of a known section. And then we need to accommodate that new section in the TUI and HTML.
Looking over the raw console output, what is happening seems to be due to live-logs enabled. This adds a new section at the beginning of the session --- live log sessionstart --. A quick fix would be to add in a new regex, and accompanying logic, to identify this section and log its contents separately. More thought is required if all the live-log sections want to be handled separately. As it stands now, that content will be included in existing sections.
Sections occurring in this order:
live log sessionstart
test session starts
ERRORS
live log collection
live log setup
live log call (several of these in succession)
warnings summary
PASSES
captured log setup
captured log call (several of these in succession)
short test summary info
lastline
In addition, make sure to include a catch-all ("other") in case a custom/unknown section is encountered. That could then be handles in the TUI/HTML with an additional section.