Open ReedJ0101 opened 2 years 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.
Running xdist with bdd is not unusual -- why not revisit/test this issue and if not working, at least update docs?
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:
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/
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?