TypeError in report_data.py
pdegroote opened this issue · 4 comments
I apologize for the lack of information, but it's not immediately clear how I can try to isolate this issue because I'm not familiar enough with pytest-html. However, sometimes I get this issue in my tests report:
..................................INTERNALERROR> Traceback (most recent call last):
INTERNALERROR> File "E:\Bld\A3\_tool\PythonNuget\python.3.8.0\tools\lib\site-packages\_pytest\main.py", line 271, in wrap_session
INTERNALERROR> session.exitstatus = doit(config, session) or 0
INTERNALERROR> File "E:\Bld\A3\_tool\PythonNuget\python.3.8.0\tools\lib\site-packages\_pytest\main.py", line 325, in _main
INTERNALERROR> config.hook.pytest_runtestloop(session=session)
INTERNALERROR> File "E:\Bld\A3\_tool\PythonNuget\python.3.8.0\tools\lib\site-packages\pluggy\_hooks.py", line 493, in __call__
INTERNALERROR> return self._hookexec(self.name, self._hookimpls, kwargs, firstresult)
INTERNALERROR> File "E:\Bld\A3\_tool\PythonNuget\python.3.8.0\tools\lib\site-packages\pluggy\_manager.py", line 115, in _hookexec
INTERNALERROR> return self._inner_hookexec(hook_name, methods, kwargs, firstresult)
INTERNALERROR> File "E:\Bld\A3\_tool\PythonNuget\python.3.8.0\tools\lib\site-packages\pluggy\_callers.py", line 152, in _multicall
INTERNALERROR> return outcome.get_result()
INTERNALERROR> File "E:\Bld\A3\_tool\PythonNuget\python.3.8.0\tools\lib\site-packages\pluggy\_result.py", line 114, in get_result
INTERNALERROR> raise exc.with_traceback(exc.__traceback__)
INTERNALERROR> File "E:\Bld\A3\_tool\PythonNuget\python.3.8.0\tools\lib\site-packages\pluggy\_callers.py", line 77, in _multicall
INTERNALERROR> res = hook_impl.function(*args)
INTERNALERROR> File "E:\Bld\A3\_tool\PythonNuget\python.3.8.0\tools\lib\site-packages\xdist\dsession.py", line 122, in pytest_runtestloop
INTERNALERROR> self.loop_once()
INTERNALERROR> File "E:\Bld\A3\_tool\PythonNuget\python.3.8.0\tools\lib\site-packages\xdist\dsession.py", line 145, in loop_once
INTERNALERROR> call(**kwargs)
INTERNALERROR> File "E:\Bld\A3\_tool\PythonNuget\python.3.8.0\tools\lib\site-packages\xdist\dsession.py", line 283, in worker_testreport
INTERNALERROR> self.config.hook.pytest_runtest_logreport(report=rep)
INTERNALERROR> File "E:\Bld\A3\_tool\PythonNuget\python.3.8.0\tools\lib\site-packages\pluggy\_hooks.py", line 493, in __call__
INTERNALERROR> return self._hookexec(self.name, self._hookimpls, kwargs, firstresult)
INTERNALERROR> File "E:\Bld\A3\_tool\PythonNuget\python.3.8.0\tools\lib\site-packages\pluggy\_manager.py", line 115, in _hookexec
INTERNALERROR> return self._inner_hookexec(hook_name, methods, kwargs, firstresult)
INTERNALERROR> File "E:\Bld\A3\_tool\PythonNuget\python.3.8.0\tools\lib\site-packages\pluggy\_callers.py", line 113, in _multicall
INTERNALERROR> raise exception.with_traceback(exception.__traceback__)
INTERNALERROR> File "E:\Bld\A3\_tool\PythonNuget\python.3.8.0\tools\lib\site-packages\pluggy\_callers.py", line 77, in _multicall
INTERNALERROR> res = hook_impl.function(*args)
INTERNALERROR> File "E:\Bld\A3\_tool\PythonNuget\python.3.8.0\tools\lib\site-packages\pytest_html\basereport.py", line 252, in pytest_runtest_logreport
INTERNALERROR> if self._report.add_test(data, report, processed_logs):
INTERNALERROR> File "E:\Bld\A3\_tool\PythonNuget\python.3.8.0\tools\lib\site-packages\pytest_html\report_data.py", line 139, in add_test
INTERNALERROR> test_data["log"] = _handle_ansi("\n".join(logs))
INTERNALERROR> TypeError: sequence item 0: expected str instance, div found
I get no extra output on which test failed, and since I have thousands it will require a considerable time investment to isolate. It seems "logs" is some kind of
_handle_ansi(str(logs))
instead of trying to join the list. It seems that this occurs for some specific test, and not even when the test fails. I don't immediately know how to get more info on the test that was executed in this place.
My setup is the following:
1: platform win32 -- Python 3.8.0, pytest-7.4.3, pluggy-1.3.0
1: plugins: flaky-3.7.0, azurepipelines-1.0.5, html-4.0.2, metadata-3.0.0, nunit-1.0.3, timeout-2.2.0, xdist-3.3.1
I recently needed to update pytest-html for an issue with unicode. I came from the following set of dependencies (where I didn't have the problem):
pytest==7.0.1
pytest-html==3.2.0
pytest-xdist==3.2.0
pytest-timeout==2.1.0
Is this sufficient information to diagnose what is going on, or can you suggest something to get more info?
I can give you some "debugging" statements to put in your code to figure out why this is happening, as it's hard for me to understand what's going without more info.
I hoped the given information would be enough. I will try to isolate the issue from our test runs, and create a minimal example. This may take a while though. If you have any pointers as to where I could get more information on the test that is being run at the crash site, that would be helpful. Many thanks!
the error indicates using a old api - the div object is most likely related to py.xml usage in old code
Thank you for the pointer. I found the issue, we have a hook where we include html images via py.xml in the test report, and this hook must add strings to the report (it added py.xml.html.div tags instead. I made these into strings. I will have an additional look to see if I can ditch the usage of old APIs. Specifically, if it helps:
def pytest_html_results_table_html(report, data):
if not hasattr(report, '_doctest_image'):
return None
if report.passed and report._doctest_image is not None:
data.pop()
data.append(str(html.div(html.img(src_=report._doctest_image, width_=400), align='left')))
Note now the explicit "str" conversion in the last line. It seems in older versions of pytest html, this was necessary.
This bug report can be closed as it is a bug in user code. Again many thanks!