pytest-dev / pytest-xdist

pytest plugin for distributed testing and loop-on-failures testing modes.
https://pytest-xdist.readthedocs.io
MIT License
1.48k stars 232 forks source link

Pytest xdist library is getting crashed #922

Closed Mayur5712 closed 12 months ago

Mayur5712 commented 1 year ago

I am trying to execute my tests parallel using xdist library, but after 10-15 tests library got crashed and execution stops.

Below is the error I got


`dkStaging.php","userkeywords": "atn:vc_w:300_h:250","allowAVAudioSessionAccess": "1"}-1] 
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 "/Users/mayur/GitRepo/sdk-automation/venv/lib/python3.9/site-packages/_pytest/main.py", line 269, in wrap_session
INTERNALERROR> E                 session.exitstatus = doit(config, session) or 0
INTERNALERROR> E               File "/Users/mayur/GitRepo/sdk-automation/venv/lib/python3.9/site-packages/_pytest/main.py", line 323, in _main
INTERNALERROR> E                 config.hook.pytest_runtestloop(session=session)
INTERNALERROR> E               File "/Users/mayur/GitRepo/sdk-automation/venv/lib/python3.9/site-packages/pluggy/hooks.py", line 286, in __call__
INTERNALERROR> E                 return self._hookexec(self, self.get_hookimpls(), kwargs)
INTERNALERROR> E               File "/Users/mayur/GitRepo/sdk-automation/venv/lib/python3.9/site-packages/pluggy/manager.py", line 93, in _hookexec
INTERNALERROR> E                 return self._inner_hookexec(hook, methods, kwargs)
INTERNALERROR> E               File "/Users/mayur/GitRepo/sdk-automation/venv/lib/python3.9/site-packages/pluggy/manager.py", line 84, in <lambda>
INTERNALERROR> E                 self._inner_hookexec = lambda hook, methods, kwargs: hook.multicall(
INTERNALERROR> E               File "/Users/mayur/GitRepo/sdk-automation/venv/lib/python3.9/site-packages/pluggy/callers.py", line 208, in _multicall
INTERNALERROR> E                 return outcome.get_result()
INTERNALERROR> E               File "/Users/mayur/GitRepo/sdk-automation/venv/lib/python3.9/site-packages/pluggy/callers.py", line 80, in get_result
INTERNALERROR> E                 raise ex[1].with_traceback(ex[2])
INTERNALERROR> E               File "/Users/mayur/GitRepo/sdk-automation/venv/lib/python3.9/site-packages/pluggy/callers.py", line 187, in _multicall
INTERNALERROR> E                 res = hook_impl.function(*args)
INTERNALERROR> E               File "/Users/mayur/GitRepo/sdk-automation/venv/lib/python3.9/site-packages/xdist/remote.py", line 112, in pytest_runtestloop
INTERNALERROR> E                 self.run_one_test(torun)
INTERNALERROR> E               File "/Users/mayur/GitRepo/sdk-automation/venv/lib/python3.9/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 "/Users/mayur/GitRepo/sdk-automation/venv/lib/python3.9/site-packages/pluggy/hooks.py", line 286, in __call__
INTERNALERROR> E                 return self._hookexec(self, self.get_hookimpls(), kwargs)
INTERNALERROR> E               File "/Users/mayur/GitRepo/sdk-automation/venv/lib/python3.9/site-packages/pluggy/manager.py", line 93, in _hookexec
INTERNALERROR> E                 return self._inner_hookexec(hook, methods, kwargs)
INTERNALERROR> E               File "/Users/mayur/GitRepo/sdk-automation/venv/lib/python3.9/site-packages/pluggy/manager.py", line 84, in <lambda>
INTERNALERROR> E                 self._inner_hookexec = lambda hook, methods, kwargs: hook.multicall(
INTERNALERROR> E               File "/Users/mayur/GitRepo/sdk-automation/venv/lib/python3.9/site-packages/pluggy/callers.py", line 208, in _multicall
INTERNALERROR> E                 return outcome.get_result()
INTERNALERROR> E               File "/Users/mayur/GitRepo/sdk-automation/venv/lib/python3.9/site-packages/pluggy/callers.py", line 80, in get_result
INTERNALERROR> E                 raise ex[1].with_traceback(ex[2])
INTERNALERROR> E               File "/Users/mayur/GitRepo/sdk-automation/venv/lib/python3.9/site-packages/pluggy/callers.py", line 187, in _multicall
INTERNALERROR> E                 res = hook_impl.function(*args)
INTERNALERROR> E               File "/Users/mayur/GitRepo/sdk-automation/venv/lib/python3.9/site-packages/_pytest/runner.py", line 109, in pytest_runtest_protocol
INTERNALERROR> E                 runtestprotocol(item, nextitem=nextitem)
INTERNALERROR> E               File "/Users/mayur/GitRepo/sdk-automation/venv/lib/python3.9/site-packages/_pytest/runner.py", line 120, in runtestprotocol
INTERNALERROR> E                 rep = call_and_report(item, "setup", log)
INTERNALERROR> E               File "/Users/mayur/GitRepo/sdk-automation/venv/lib/python3.9/site-packages/_pytest/runner.py", line 219, in call_and_report
INTERNALERROR> E                 hook.pytest_runtest_logreport(report=report)
INTERNALERROR> E               File "/Users/mayur/GitRepo/sdk-automation/venv/lib/python3.9/site-packages/pluggy/hooks.py", line 286, in __call__
INTERNALERROR> E                 return self._hookexec(self, self.get_hookimpls(), kwargs)
INTERNALERROR> E               File "/Users/mayur/GitRepo/sdk-automation/venv/lib/python3.9/site-packages/pluggy/manager.py", line 93, in _hookexec
INTERNALERROR> E                 return self._inner_hookexec(hook, methods, kwargs)
INTERNALERROR> E               File "/Users/mayur/GitRepo/sdk-automation/venv/lib/python3.9/site-packages/pluggy/manager.py", line 84, in <lambda>
INTERNALERROR> E                 self._inner_hookexec = lambda hook, methods, kwargs: hook.multicall(
INTERNALERROR> E               File "/Users/mayur/GitRepo/sdk-automation/venv/lib/python3.9/site-packages/pluggy/callers.py", line 208, in _multicall
INTERNALERROR> E                 return outcome.get_result()
INTERNALERROR> E               File "/Users/mayur/GitRepo/sdk-automation/venv/lib/python3.9/site-packages/pluggy/callers.py", line 80, in get_result
INTERNALERROR> E                 raise ex[1].with_traceback(ex[2])
INTERNALERROR> E               File "/Users/mayur/GitRepo/sdk-automation/venv/lib/python3.9/site-packages/pluggy/callers.py", line 187, in _multicall
INTERNALERROR> E                 res = hook_impl.function(*args)
INTERNALERROR> E               File "/Users/mayur/GitRepo/sdk-automation/venv/lib/python3.9/site-packages/xdist/remote.py", line 183, in pytest_runtest_logreport
INTERNALERROR> E                 assert self.session.items[self.item_index].nodeid == report.nodeid
INTERNALERROR> E             AssertionError
INTERNALERROR> E           assert False
INTERNALERROR> 
INTERNALERROR> venv/lib/python3.9/site-packages/xdist/dsession.py:190: AssertionError
INTERNALERROR> Traceback (most recent call last):
INTERNALERROR>   File "/Users/mayur/GitRepo/sdk-automation/venv/lib/python3.9/site-packages/_pytest/main.py", line 269, in wrap_session
INTERNALERROR>     session.exitstatus = doit(config, session) or 0
INTERNALERROR>   File "/Users/mayur/GitRepo/sdk-automation/venv/lib/python3.9/site-packages/_pytest/main.py", line 323, in _main
INTERNALERROR>     config.hook.pytest_runtestloop(session=session)
INTERNALERROR>   File "/Users/mayur/GitRepo/sdk-automation/venv/lib/python3.9/site-packages/pluggy/hooks.py", line 286, in __call__
INTERNALERROR>     return self._hookexec(self, self.get_hookimpls(), kwargs)
INTERNALERROR>   File "/Users/mayur/GitRepo/sdk-automation/venv/lib/python3.9/site-packages/pluggy/manager.py", line 93, in _hookexec
INTERNALERROR>     return self._inner_hookexec(hook, methods, kwargs)
INTERNALERROR>   File "/Users/mayur/GitRepo/sdk-automation/venv/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/mayur/GitRepo/sdk-automation/venv/lib/python3.9/site-packages/pluggy/callers.py", line 208, in _multicall
INTERNALERROR>     return outcome.get_result()
INTERNALERROR>   File "/Users/mayur/GitRepo/sdk-automation/venv/lib/python3.9/site-packages/pluggy/callers.py", line 80, in get_result
INTERNALERROR>     raise ex[1].with_traceback(ex[2])
INTERNALERROR>   File "/Users/mayur/GitRepo/sdk-automation/venv/lib/python3.9/site-packages/pluggy/callers.py", line 187, in _multicall
INTERNALERROR>     res = hook_impl.function(*args)
INTERNALERROR>   File "/Users/mayur/GitRepo/sdk-automation/venv/lib/python3.9/site-packages/xdist/dsession.py", line 115, in pytest_runtestloop
INTERNALERROR>     self.loop_once()
INTERNALERROR>   File "/Users/mayur/GitRepo/sdk-automation/venv/lib/python3.9/site-packages/xdist/dsession.py", line 138, in loop_once
INTERNALERROR>     call(**kwargs)
INTERNALERROR>   File "/Users/mayur/GitRepo/sdk-automation/venv/lib/python3.9/site-packages/xdist/dsession.py", line 177, in worker_workerfinished
INTERNALERROR>     assert not crashitem, (crashitem, node)
INTERNALERROR> AssertionError: ('TestScripts/MRAID/test_audio_volume_change_event.py::TestAudioVolumeChange::test_allowAVAudioSessionAccess[banner-{"...php/sdkStaging.php","userkeywords": "atn:vc_w:300_h:250","allowAVAudioSessionAccess": "1"}-1]', <WorkerController gw1>)
INTERNALERROR> assert not 'TestScripts/MRAID/test_audio_volume_change_event.py::TestAudioVolumeChange::test_allowAVAudioSessionAccess[banner-{"a...ms.pubmatic.com:8443/sdk/php/sdkStaging.php","userkeywords": "atn:vc_w:300_h:250","allowAVAudioSessionAccess": "1"}-1]'`
RonnyPfannschmidt commented 12 months ago

Closing as user error, random objects in tests ids Are not supported, please explicitly name them using pytest.param

nck974 commented 4 months ago

For anyone getting the same, if you are using something dynamic like this:

@pytest.mark.parametrize(
    "test_time,test_scenario",
    [
        (datetime.now(), MyEnum.MY_VALUE_1),
        (datetime.now() - relativedelta(years=17), MyEnum.MY_VALUE_1),
    ],
)

Change it to this:

@pytest.mark.parametrize(
    "test_time,test_scenario",
    [
        pytest.param(datetime.now(), MyEnum.MY_VALUE_1, id="name_of_my_test_1"),
        pytest.param(datetime.now() - relativedelta(years=17), MyEnum.MY_VALUE_1, id="name_of_my_test_2"),
    ],
)