slavos1 / pytest-bdd-html

pytest plugin to display BDD info in HTML test report
MIT License
3 stars 0 forks source link

pytest-xdist parallel execution #6

Open ReedJ0101 opened 2 years ago

ReedJ0101 commented 2 years ago

I like this plugin, however it currently only works when running serially. I get the below error when running with multiple workers using pytest-xdist.

Are there plans to get this working with parallel test runs?

platform win32 -- Python 3.8.0, pytest-7.2.0, pluggy-1.0.0
rootdir: C:\projects\Automation POC
plugins: base-url-2.0.0, bdd-6.1.0, bdd-html-0.1.13a0, html-3.2.0, metadata-2.0.4, playwright-0.3.0, xdist-3.0.2
gw0 [2] / gw1 [2]
INTERNALERROR> def worker_internal_error(self, node, formatted_error):
INTERNALERROR>         """
INTERNALERROR>         pytest_internalerror() was called on the worker.
INTERNALERROR>
INTERNALERROR>         pytest_internalerror() arguments are an excinfo and an excrepr, which can't
INTERNALERROR>         be serialized, so we go with a poor man's solution of raising an exception
INTERNALERROR>         here ourselves using the formatted message.
INTERNALERROR>         """
INTERNALERROR>         self._active_nodes.remove(node)
INTERNALERROR>         try:
INTERNALERROR> >           assert False, formatted_error
INTERNALERROR> E           AssertionError: Traceback (most recent call last):
INTERNALERROR> E               File "C:\Users\jreed\.virtualenvs\venv\lib\site-packages\execnet\gateway_base.py", line 1400, in _save
INTERNALERROR> E                 dispatch = self._dispatch[tp]
INTERNALERROR> E             KeyError: <class 'pytest_bdd.parser.Step'>
INTERNALERROR> E
INTERNALERROR> E             During handling of the above exception, another exception occurred:
INTERNALERROR> E
INTERNALERROR> E             Traceback (most recent call last):
INTERNALERROR> E               File "C:\Users\jreed\.virtualenvs\venv\lib\site-packages\_pytest\main.py", line 270, in wrap_session
INTERNALERROR> E                 session.exitstatus = doit(config, session) or 0
INTERNALERROR> E               File "C:\Users\jreed\.virtualenvs\venv\lib\site-packages\_pytest\main.py", line 324, in _main
INTERNALERROR> E                 config.hook.pytest_runtestloop(session=session)
INTERNALERROR> E               File "C:\Users\jreed\.virtualenvs\venv\lib\site-packages\pluggy\_hooks.py", line 265, in __call__
INTERNALERROR> E                 return self._hookexec(self.name, self.get_hookimpls(), kwargs, firstresult)
INTERNALERROR> E               File "C:\Users\jreed\.virtualenvs\venv\lib\site-packages\pluggy\_manager.py", line 80, in _hookexec
INTERNALERROR> E                 return self._inner_hookexec(hook_name, methods, kwargs, firstresult)
INTERNALERROR> E               File "C:\Users\jreed\.virtualenvs\venv\lib\site-packages\pluggy\_callers.py", line 60, in _multicall
INTERNALERROR> E                 return outcome.get_result()
INTERNALERROR> E               File "C:\Users\jreed\.virtualenvs\venv\lib\site-packages\pluggy\_result.py", line 60, in get_result
INTERNALERROR> E                 raise ex[1].with_traceback(ex[2])
INTERNALERROR> E               File "C:\Users\jreed\.virtualenvs\venv\lib\site-packages\pluggy\_callers.py", line 39, in _multicall
INTERNALERROR> E                 res = hook_impl.function(*args)
INTERNALERROR> E               File "C:\Users\jreed\.virtualenvs\venv\lib\site-packages\xdist\remote.py", line 115, in pytest_runtestloop
INTERNALERROR> E                 self.run_one_test(torun)
INTERNALERROR> E               File "C:\Users\jreed\.virtualenvs\venv\lib\site-packages\xdist\remote.py", line 131, in run_one_test
INTERNALERROR> E                 self.config.hook.pytest_runtest_protocol(item=item, nextitem=nextitem)
INTERNALERROR> E               File "C:\Users\jreed\.virtualenvs\venv\lib\site-packages\pluggy\_hooks.py", line 265, in __call__
INTERNALERROR> E                 return self._hookexec(self.name, self.get_hookimpls(), kwargs, firstresult)
INTERNALERROR> E               File "C:\Users\jreed\.virtualenvs\venv\lib\site-packages\pluggy\_manager.py", line 80, in _hookexec
INTERNALERROR> E                 return self._inner_hookexec(hook_name, methods, kwargs, firstresult)
INTERNALERROR> E               File "C:\Users\jreed\.virtualenvs\venv\lib\site-packages\pluggy\_callers.py", line 60, in _multicall
INTERNALERROR> E                 return outcome.get_result()
INTERNALERROR> E               File "C:\Users\jreed\.virtualenvs\venv\lib\site-packages\pluggy\_result.py", line 60, in get_result
INTERNALERROR> E                 raise ex[1].with_traceback(ex[2])
INTERNALERROR> E               File "C:\Users\jreed\.virtualenvs\venv\lib\site-packages\pluggy\_callers.py", line 39, in _multicall
INTERNALERROR> E                 res = hook_impl.function(*args)
INTERNALERROR> E               File "C:\Users\jreed\.virtualenvs\venv\lib\site-packages\_pytest\runner.py", line 112, in pytest_runtest_protocol
INTERNALERROR> E                 runtestprotocol(item, nextitem=nextitem)
INTERNALERROR> E               File "C:\Users\jreed\.virtualenvs\venv\lib\site-packages\_pytest\runner.py", line 131, in runtestprotocol
INTERNALERROR> E                 reports.append(call_and_report(item, "call", log))
INTERNALERROR> E               File "C:\Users\jreed\.virtualenvs\venv\lib\site-packages\_pytest\runner.py", line 224, in call_and_report
INTERNALERROR> E                 hook.pytest_runtest_logreport(report=report)
INTERNALERROR> E               File "C:\Users\jreed\.virtualenvs\venv\lib\site-packages\pluggy\_hooks.py", line 265, in __call__
INTERNALERROR> E                 return self._hookexec(self.name, self.get_hookimpls(), kwargs, firstresult)
INTERNALERROR> E               File "C:\Users\jreed\.virtualenvs\venv\lib\site-packages\pluggy\_manager.py", line 80, in _hookexec
INTERNALERROR> E                 return self._inner_hookexec(hook_name, methods, kwargs, firstresult)
INTERNALERROR> E               File "C:\Users\jreed\.virtualenvs\venv\lib\site-packages\pluggy\_callers.py", line 60, in _multicall
INTERNALERROR> E                 return outcome.get_result()
INTERNALERROR> E               File "C:\Users\jreed\.virtualenvs\venv\lib\site-packages\pluggy\_result.py", line 60, in get_result
INTERNALERROR> E                 raise ex[1].with_traceback(ex[2])
INTERNALERROR> E               File "C:\Users\jreed\.virtualenvs\venv\lib\site-packages\pluggy\_callers.py", line 39, in _multicall
INTERNALERROR> E                 res = hook_impl.function(*args)
INTERNALERROR> E               File "C:\Users\jreed\.virtualenvs\venv\lib\site-packages\xdist\remote.py", line 184, in pytest_runtest_logreport
INTERNALERROR> E                 self.sendevent("testreport", data=data)
INTERNALERROR> E               File "C:\Users\jreed\.virtualenvs\venv\lib\site-packages\xdist\remote.py", line 69, in sendevent
INTERNALERROR> E                 self.channel.send((name, kwargs))
INTERNALERROR> E               File "C:\Users\jreed\.virtualenvs\venv\lib\site-packages\execnet\gateway_base.py", line 729, in send
INTERNALERROR> E                 self.gateway._send(Message.CHANNEL_DATA, self.id, dumps_internal(item))
INTERNALERROR> E               File "C:\Users\jreed\.virtualenvs\venv\lib\site-packages\execnet\gateway_base.py", line 1371, in dumps_internal
INTERNALERROR> E                 return _Serializer().save(obj)
INTERNALERROR> E               File "C:\Users\jreed\.virtualenvs\venv\lib\site-packages\execnet\gateway_base.py", line 1389, in save
INTERNALERROR> E                 self._save(obj)
INTERNALERROR> E               File "C:\Users\jreed\.virtualenvs\venv\lib\site-packages\execnet\gateway_base.py", line 1407, in _save
INTERNALERROR> E                 dispatch(self, obj)
INTERNALERROR> E               File "C:\Users\jreed\.virtualenvs\venv\lib\site-packages\execnet\gateway_base.py", line 1494, in save_tuple
INTERNALERROR> E                 self._save(item)
INTERNALERROR> E               File "C:\Users\jreed\.virtualenvs\venv\lib\site-packages\execnet\gateway_base.py", line 1407, in _save
INTERNALERROR> E                 dispatch(self, obj)
INTERNALERROR> E               File "C:\Users\jreed\.virtualenvs\venv\lib\site-packages\execnet\gateway_base.py", line 1490, in save_dict
INTERNALERROR> E                 self._write_setitem(key, value)
INTERNALERROR> E               File "C:\Users\jreed\.virtualenvs\venv\lib\site-packages\execnet\gateway_base.py", line 1484, in _write_setitem
INTERNALERROR> E                 self._save(value)
INTERNALERROR> E               File "C:\Users\jreed\.virtualenvs\venv\lib\site-packages\execnet\gateway_base.py", line 1407, in _save
INTERNALERROR> E                 dispatch(self, obj)
INTERNALERROR> E               File "C:\Users\jreed\.virtualenvs\venv\lib\site-packages\execnet\gateway_base.py", line 1490, in save_dict
INTERNALERROR> E                 self._write_setitem(key, value)
INTERNALERROR> E               File "C:\Users\jreed\.virtualenvs\venv\lib\site-packages\execnet\gateway_base.py", line 1484, in _write_setitem
INTERNALERROR> E                 self._save(value)
INTERNALERROR> E               File "C:\Users\jreed\.virtualenvs\venv\lib\site-packages\execnet\gateway_base.py", line 1407, in _save
INTERNALERROR> E                 dispatch(self, obj)
INTERNALERROR> E               File "C:\Users\jreed\.virtualenvs\venv\lib\site-packages\execnet\gateway_base.py", line 1480, in save_list
INTERNALERROR> E                 self._write_setitem(i, item)
INTERNALERROR> E               File "C:\Users\jreed\.virtualenvs\venv\lib\site-packages\execnet\gateway_base.py", line 1484, in _write_setitem
INTERNALERROR> E                 self._save(value)
INTERNALERROR> E               File "C:\Users\jreed\.virtualenvs\venv\lib\site-packages\execnet\gateway_base.py", line 1407, in _save
INTERNALERROR> E                 dispatch(self, obj)
INTERNALERROR> E               File "C:\Users\jreed\.virtualenvs\venv\lib\site-packages\execnet\gateway_base.py", line 1494, in save_tuple
INTERNALERROR> E                 self._save(item)
INTERNALERROR> E               File "C:\Users\jreed\.virtualenvs\venv\lib\site-packages\execnet\gateway_base.py", line 1407, in _save
INTERNALERROR> E                 dispatch(self, obj)
INTERNALERROR> E               File "C:\Users\jreed\.virtualenvs\venv\lib\site-packages\execnet\gateway_base.py", line 1490, in save_dict
INTERNALERROR> E                 self._write_setitem(key, value)
INTERNALERROR> E               File "C:\Users\jreed\.virtualenvs\venv\lib\site-packages\execnet\gateway_base.py", line 1484, in _write_setitem
INTERNALERROR> E                 self._save(value)
INTERNALERROR> E               File "C:\Users\jreed\.virtualenvs\venv\lib\site-packages\execnet\gateway_base.py", line 1407, in _save
INTERNALERROR> E                 dispatch(self, obj)
INTERNALERROR> E               File "C:\Users\jreed\.virtualenvs\venv\lib\site-packages\execnet\gateway_base.py", line 1480, in save_list
INTERNALERROR> E                 self._write_setitem(i, item)
INTERNALERROR> E               File "C:\Users\jreed\.virtualenvs\venv\lib\site-packages\execnet\gateway_base.py", line 1484, in _write_setitem
INTERNALERROR> E                 self._save(value)
INTERNALERROR> E               File "C:\Users\jreed\.virtualenvs\venv\lib\site-packages\execnet\gateway_base.py", line 1405, in _save
INTERNALERROR> E                 raise DumpError("can't serialize {}".format(tp))
INTERNALERROR> E             execnet.gateway_base.DumpError: can't serialize <class 'pytest_bdd.parser.Step'>
INTERNALERROR> E           assert False
INTERNALERROR>
INTERNALERROR> C:\Users\jreed\.virtualenvs\venv\lib\site-packages\xdist\dsession.py:190: AssertionError
INTERNALERROR> def worker_internal_error(self, node, formatted_error):
INTERNALERROR>         """
INTERNALERROR>         pytest_internalerror() was called on the worker.
INTERNALERROR>
INTERNALERROR>         pytest_internalerror() arguments are an excinfo and an excrepr, which can't
INTERNALERROR>         be serialized, so we go with a poor man's solution of raising an exception
INTERNALERROR>         here ourselves using the formatted message.
INTERNALERROR>         """
INTERNALERROR>         self._active_nodes.remove(node)
INTERNALERROR>         try:
INTERNALERROR> >           assert False, formatted_error
INTERNALERROR> E           AssertionError: Traceback (most recent call last):
INTERNALERROR> E               File "C:\Users\jreed\.virtualenvs\venv\lib\site-packages\execnet\gateway_base.py", line 1400, in _save
INTERNALERROR> E                 dispatch = self._dispatch[tp]
INTERNALERROR> E             KeyError: <class 'pytest_bdd.parser.Step'>
INTERNALERROR> E
INTERNALERROR> E             During handling of the above exception, another exception occurred:
INTERNALERROR> E
INTERNALERROR> E             Traceback (most recent call last):
INTERNALERROR> E               File "C:\Users\jreed\.virtualenvs\venv\lib\site-packages\_pytest\main.py", line 270, in wrap_session
INTERNALERROR> E                 session.exitstatus = doit(config, session) or 0
INTERNALERROR> E               File "C:\Users\jreed\.virtualenvs\venv\lib\site-packages\_pytest\main.py", line 324, in _main
INTERNALERROR> E                 config.hook.pytest_runtestloop(session=session)
INTERNALERROR> E               File "C:\Users\jreed\.virtualenvs\venv\lib\site-packages\pluggy\_hooks.py", line 265, in __call__
INTERNALERROR> E                 return self._hookexec(self.name, self.get_hookimpls(), kwargs, firstresult)
INTERNALERROR> E               File "C:\Users\jreed\.virtualenvs\venv\lib\site-packages\pluggy\_manager.py", line 80, in _hookexec
INTERNALERROR> E                 return self._inner_hookexec(hook_name, methods, kwargs, firstresult)
INTERNALERROR> E               File "C:\Users\jreed\.virtualenvs\venv\lib\site-packages\pluggy\_callers.py", line 60, in _multicall
INTERNALERROR> E                 return outcome.get_result()
INTERNALERROR> E               File "C:\Users\jreed\.virtualenvs\venv\lib\site-packages\pluggy\_result.py", line 60, in get_result
INTERNALERROR> E                 raise ex[1].with_traceback(ex[2])
INTERNALERROR> E               File "C:\Users\jreed\.virtualenvs\venv\lib\site-packages\pluggy\_callers.py", line 39, in _multicall
INTERNALERROR> E                 res = hook_impl.function(*args)
INTERNALERROR> E               File "C:\Users\jreed\.virtualenvs\venv\lib\site-packages\xdist\remote.py", line 115, in pytest_runtestloop
INTERNALERROR> E                 self.run_one_test(torun)
INTERNALERROR> E               File "C:\Users\jreed\.virtualenvs\venv\lib\site-packages\xdist\remote.py", line 131, in run_one_test
INTERNALERROR> E                 self.config.hook.pytest_runtest_protocol(item=item, nextitem=nextitem)
INTERNALERROR> E               File "C:\Users\jreed\.virtualenvs\venv\lib\site-packages\pluggy\_hooks.py", line 265, in __call__
INTERNALERROR> E                 return self._hookexec(self.name, self.get_hookimpls(), kwargs, firstresult)
INTERNALERROR> E               File "C:\Users\jreed\.virtualenvs\venv\lib\site-packages\pluggy\_manager.py", line 80, in _hookexec
INTERNALERROR> E                 return self._inner_hookexec(hook_name, methods, kwargs, firstresult)
INTERNALERROR> E               File "C:\Users\jreed\.virtualenvs\venv\lib\site-packages\pluggy\_callers.py", line 60, in _multicall
INTERNALERROR> E                 return outcome.get_result()
INTERNALERROR> E               File "C:\Users\jreed\.virtualenvs\venv\lib\site-packages\pluggy\_result.py", line 60, in get_result
INTERNALERROR> E                 raise ex[1].with_traceback(ex[2])
INTERNALERROR> E               File "C:\Users\jreed\.virtualenvs\venv\lib\site-packages\pluggy\_callers.py", line 39, in _multicall
INTERNALERROR> E                 res = hook_impl.function(*args)
INTERNALERROR> E               File "C:\Users\jreed\.virtualenvs\venv\lib\site-packages\_pytest\runner.py", line 112, in pytest_runtest_protocol
INTERNALERROR> E                 runtestprotocol(item, nextitem=nextitem)
INTERNALERROR> E               File "C:\Users\jreed\.virtualenvs\venv\lib\site-packages\_pytest\runner.py", line 131, in runtestprotocol
INTERNALERROR> E                 reports.append(call_and_report(item, "call", log))
INTERNALERROR> E               File "C:\Users\jreed\.virtualenvs\venv\lib\site-packages\_pytest\runner.py", line 224, in call_and_report
INTERNALERROR> E                 hook.pytest_runtest_logreport(report=report)
INTERNALERROR> E               File "C:\Users\jreed\.virtualenvs\venv\lib\site-packages\pluggy\_hooks.py", line 265, in __call__
INTERNALERROR> E                 return self._hookexec(self.name, self.get_hookimpls(), kwargs, firstresult)
INTERNALERROR> E               File "C:\Users\jreed\.virtualenvs\venv\lib\site-packages\pluggy\_manager.py", line 80, in _hookexec
INTERNALERROR> E                 return self._inner_hookexec(hook_name, methods, kwargs, firstresult)
INTERNALERROR> E               File "C:\Users\jreed\.virtualenvs\venv\lib\site-packages\pluggy\_callers.py", line 60, in _multicall
INTERNALERROR> E                 return outcome.get_result()
INTERNALERROR> E               File "C:\Users\jreed\.virtualenvs\venv\lib\site-packages\pluggy\_result.py", line 60, in get_result
INTERNALERROR> E                 raise ex[1].with_traceback(ex[2])
INTERNALERROR> E               File "C:\Users\jreed\.virtualenvs\venv\lib\site-packages\pluggy\_callers.py", line 39, in _multicall
INTERNALERROR> E                 res = hook_impl.function(*args)
INTERNALERROR> E               File "C:\Users\jreed\.virtualenvs\venv\lib\site-packages\xdist\remote.py", line 184, in pytest_runtest_logreport
INTERNALERROR> E                 self.sendevent("testreport", data=data)
INTERNALERROR> E               File "C:\Users\jreed\.virtualenvs\venv\lib\site-packages\xdist\remote.py", line 69, in sendevent
INTERNALERROR> E                 self.channel.send((name, kwargs))
INTERNALERROR> E               File "C:\Users\jreed\.virtualenvs\venv\lib\site-packages\execnet\gateway_base.py", line 729, in send
INTERNALERROR> E                 self.gateway._send(Message.CHANNEL_DATA, self.id, dumps_internal(item))
INTERNALERROR> E               File "C:\Users\jreed\.virtualenvs\venv\lib\site-packages\execnet\gateway_base.py", line 1371, in dumps_internal
INTERNALERROR> E                 return _Serializer().save(obj)
INTERNALERROR> E               File "C:\Users\jreed\.virtualenvs\venv\lib\site-packages\execnet\gateway_base.py", line 1389, in save
INTERNALERROR> E                 self._save(obj)
INTERNALERROR> E               File "C:\Users\jreed\.virtualenvs\venv\lib\site-packages\execnet\gateway_base.py", line 1407, in _save
INTERNALERROR> E                 dispatch(self, obj)
INTERNALERROR> E               File "C:\Users\jreed\.virtualenvs\venv\lib\site-packages\execnet\gateway_base.py", line 1494, in save_tuple
INTERNALERROR> E                 self._save(item)
INTERNALERROR> E               File "C:\Users\jreed\.virtualenvs\venv\lib\site-packages\execnet\gateway_base.py", line 1407, in _save
INTERNALERROR> E                 dispatch(self, obj)
INTERNALERROR> E               File "C:\Users\jreed\.virtualenvs\venv\lib\site-packages\execnet\gateway_base.py", line 1490, in save_dict
INTERNALERROR> E                 self._write_setitem(key, value)
INTERNALERROR> E               File "C:\Users\jreed\.virtualenvs\venv\lib\site-packages\execnet\gateway_base.py", line 1484, in _write_setitem
INTERNALERROR> E                 self._save(value)
INTERNALERROR> E               File "C:\Users\jreed\.virtualenvs\venv\lib\site-packages\execnet\gateway_base.py", line 1407, in _save
INTERNALERROR> E                 dispatch(self, obj)
INTERNALERROR> E               File "C:\Users\jreed\.virtualenvs\venv\lib\site-packages\execnet\gateway_base.py", line 1490, in save_dict
INTERNALERROR> E                 self._write_setitem(key, value)
INTERNALERROR> E               File "C:\Users\jreed\.virtualenvs\venv\lib\site-packages\execnet\gateway_base.py", line 1484, in _write_setitem
INTERNALERROR> E                 self._save(value)
INTERNALERROR> E               File "C:\Users\jreed\.virtualenvs\venv\lib\site-packages\execnet\gateway_base.py", line 1407, in _save
INTERNALERROR> E                 dispatch(self, obj)
INTERNALERROR> E               File "C:\Users\jreed\.virtualenvs\venv\lib\site-packages\execnet\gateway_base.py", line 1480, in save_list
INTERNALERROR> E                 self._write_setitem(i, item)
INTERNALERROR> E               File "C:\Users\jreed\.virtualenvs\venv\lib\site-packages\execnet\gateway_base.py", line 1484, in _write_setitem
INTERNALERROR> E                 self._save(value)
INTERNALERROR> E               File "C:\Users\jreed\.virtualenvs\venv\lib\site-packages\execnet\gateway_base.py", line 1407, in _save
INTERNALERROR> E                 dispatch(self, obj)
INTERNALERROR> E               File "C:\Users\jreed\.virtualenvs\venv\lib\site-packages\execnet\gateway_base.py", line 1494, in save_tuple
INTERNALERROR> E                 self._save(item)
INTERNALERROR> E               File "C:\Users\jreed\.virtualenvs\venv\lib\site-packages\execnet\gateway_base.py", line 1407, in _save
INTERNALERROR> E                 dispatch(self, obj)
INTERNALERROR> E               File "C:\Users\jreed\.virtualenvs\venv\lib\site-packages\execnet\gateway_base.py", line 1490, in save_dict
INTERNALERROR> E                 self._write_setitem(key, value)
INTERNALERROR> E               File "C:\Users\jreed\.virtualenvs\venv\lib\site-packages\execnet\gateway_base.py", line 1484, in _write_setitem
INTERNALERROR> E                 self._save(value)
INTERNALERROR> E               File "C:\Users\jreed\.virtualenvs\venv\lib\site-packages\execnet\gateway_base.py", line 1407, in _save
INTERNALERROR> E                 dispatch(self, obj)
INTERNALERROR> E               File "C:\Users\jreed\.virtualenvs\venv\lib\site-packages\execnet\gateway_base.py", line 1480, in save_list
INTERNALERROR> E                 self._write_setitem(i, item)
INTERNALERROR> E               File "C:\Users\jreed\.virtualenvs\venv\lib\site-packages\execnet\gateway_base.py", line 1484, in _write_setitem
INTERNALERROR> E                 self._save(value)
INTERNALERROR> E               File "C:\Users\jreed\.virtualenvs\venv\lib\site-packages\execnet\gateway_base.py", line 1405, in _save
INTERNALERROR> E                 raise DumpError("can't serialize {}".format(tp))
INTERNALERROR> E             execnet.gateway_base.DumpError: can't serialize <class 'pytest_bdd.parser.Step'>
INTERNALERROR> E           assert False
INTERNALERROR>
INTERNALERROR> C:\Users\jreed\.virtualenvs\venv\lib\site-packages\xdist\dsession.py:190: AssertionError
slavos1 commented 1 year ago

Thanks for the likes @ReedJ0101 and sorry for the late reply!

Looking at the error:

E execnet.gateway_base.DumpError: can't serialize <class 'pytest_bdd.parser.Step'>

looks more like pytest-dev/pytest-bdd limitation, so please consider opening an issue with that project.

slavos1 commented 10 months ago

Running xdist with bdd is not unusual -- why not revisit/test this issue and if not working, at least update docs?

slavos1 commented 8 months ago

pytest-bdd works with pytest-xdist and they have tests to prove it. More reasons to fix this issue.

For reference, all related pytest-bdd issues:

slavos1 commented 5 months ago

Did some investigation.

The error comes from pytest-xdist's dumps_internal:

>>> from execnet.gateway_base import dumps_internal
>>> import pytest_bdd
>>> dumps_internal(pytest_bdd.parser.Step(1,2,3,4,5))
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File ".../lib/python3.9/site-packages/execnet/gateway_base.py", line 1629, in dumps_internal
    return _Serializer().save(obj)  # type: ignore[return-value]
  File ".../lib/python3.9/site-packages/execnet/gateway_base.py", line 1647, in save
    self._save(obj)
  File ".../lib/python3.9/site-packages/execnet/gateway_base.py", line 1665, in _save
    raise DumpError(f"can't serialize {tp}") from None
execnet.gateway_base.DumpError: can't serialize <class 'pytest_bdd.parser.Step'>

# works ok, dumps
>>> pickle.dumps(pytest_bdd.parser.Step(1,2,3,4,5))

Seems if the Step class had a save_Step method, this would have been avoided.

But, why do we need this? I suspect this is due to saving Step's (steps=scenario.steps) in the pytest_bdd_before_scenario hook. And we need scenario.steps in pytest_html_results_table_row but we actually need just Step.type and Step.name.

So, one possible solution would be:

# instead of steps=scenario.steps in pytest_bdd_before_scenario:
("scenario", dict(name=scenario.name, steps=tuple({a:getattr(s, a) for a in ['type','name']} for s in scenario.steps)),

# then in _format_step
# step.type -> step['type']
# step.name -> step['name']

And, sure enough, dumps_internal has not problem dumping such tuple of dict's. \o/