title: How can I resolve an error running pytest in parallel via xdist in bitbucket pipelines
body: <p>We execute our unit tests for our python repo within a bitbucket pipeline. Recently we started using the pytest-xdist (<a href="https://pypi.org/project/pytest-xdist/" rel="nofollow noreferrer">https://pypi.org/project/pytest-xdist/</a>) package and successfully run our unit tests in parallel when running locally via the <code>coverage run -m pytest -n auto</code> command. This executes all unit tests across all available cpus on our local machines. However when we run the tests with the same command via a bitbucket pipeline we encounter the following exception. Is there any advice on how to resolve this?</p>
  <pre><code>+ coverage run -m pytest -n auto
  ============================= test session starts ==============================
  platform linux -- Python 3.7.5, pytest-5.4.3, py-1.10.0, pluggy-0.13.1
  rootdir: /opt/atlassian/pipelines/agent/build
  plugins: celery-4.4.7, forked-1.3.0, xdist-2.2.1, mock-3.5.1
  gw0 I / gw1 I / gw2 I / gw3 I
  INTERNALERROR&gt; def worker_internal_error(self, node, formatted_error):
  INTERNALERROR&gt;         &quot;&quot;&quot;
  INTERNALERROR&gt;         pytest_internalerror() was called on the worker.
  INTERNALERROR&gt;     
  INTERNALERROR&gt;         pytest_internalerror() arguments are an excinfo and an excrepr, which can't
  INTERNALERROR&gt;         be serialized, so we go with a poor man's solution of raising an exception
  INTERNALERROR&gt;         here ourselves using the formatted message.
  INTERNALERROR&gt;         &quot;&quot;&quot;
  INTERNALERROR&gt;         self._active_nodes.remove(node)
  INTERNALERROR&gt;         try:
  INTERNALERROR&gt; &gt;           assert False, formatted_error
  INTERNALERROR&gt; E           AssertionError: Traceback (most recent call last):
  INTERNALERROR&gt; E               File &quot;/usr/local/lib/python3.7/site-packages/_pytest/main.py&quot;, line 191, in wrap_session
  INTERNALERROR&gt; E                 session.exitstatus = doit(config, session) or 0
  INTERNALERROR&gt; E               File &quot;/usr/local/lib/python3.7/site-packages/_pytest/main.py&quot;, line 246, in _main
  INTERNALERROR&gt; E                 config.hook.pytest_collection(session=session)
  INTERNALERROR&gt; E               File &quot;/usr/local/lib/python3.7/site-packages/pluggy/hooks.py&quot;, line 286, in __call__
  INTERNALERROR&gt; E                 return self._hookexec(self, self.get_hookimpls(), kwargs)
  INTERNALERROR&gt; E               File &quot;/usr/local/lib/python3.7/site-packages/pluggy/manager.py&quot;, line 93, in _hookexec
  INTERNALERROR&gt; E                 return self._inner_hookexec(hook, methods, kwargs)
  INTERNALERROR&gt; E               File &quot;/usr/local/lib/python3.7/site-packages/pluggy/manager.py&quot;, line 87, in &lt;lambda&gt;
  INTERNALERROR&gt; E                 firstresult=hook.spec.opts.get(&quot;firstresult&quot;) if hook.spec else False,
  INTERNALERROR&gt; E               File &quot;/usr/local/lib/python3.7/site-packages/pluggy/callers.py&quot;, line 208, in _multicall
  INTERNALERROR&gt; E                 return outcome.get_result()
  INTERNALERROR&gt; E               File &quot;/usr/local/lib/python3.7/site-packages/pluggy/callers.py&quot;, line 80, in get_result
  INTERNALERROR&gt; E                 raise ex[1].with_traceback(ex[2])
  INTERNALERROR&gt; E               File &quot;/usr/local/lib/python3.7/site-packages/pluggy/callers.py&quot;, line 187, in _multicall
  INTERNALERROR&gt; E                 res = hook_impl.function(*args)
  INTERNALERROR&gt; E               File &quot;/usr/local/lib/python3.7/site-packages/_pytest/main.py&quot;, line 257, in pytest_collection
  INTERNALERROR&gt; E                 return session.perform_collect()
  INTERNALERROR&gt; E               File &quot;/usr/local/lib/python3.7/site-packages/_pytest/main.py&quot;, line 453, in perform_collect
  INTERNALERROR&gt; E                 self.config.pluginmanager.check_pending()
  INTERNALERROR&gt; E               File &quot;/usr/local/lib/python3.7/site-packages/pluggy/manager.py&quot;, line 277, in check_pending
  INTERNALERROR&gt; E                 % (name, hookimpl.plugin),
  INTERNALERROR&gt; E             pluggy.manager.PluginValidationError: unknown hook 'pytest_warning_recorded' in plugin &lt;__channelexec__.WorkerInteractor object at 0x7f11772d84d0&gt;
  INTERNALERROR&gt; E           assert False
  INTERNALERROR&gt; 
  INTERNALERROR&gt; /usr/local/lib/python3.7/site-packages/xdist/dsession.py:187: AssertionError
  INTERNALERROR&gt; Traceback (most recent call last):
  INTERNALERROR&gt;   File &quot;/usr/local/lib/python3.7/site-packages/_pytest/main.py&quot;, line 191, in wrap_session
  INTERNALERROR&gt;     session.exitstatus = doit(config, session) or 0
  INTERNALERROR&gt;   File &quot;/usr/local/lib/python3.7/site-packages/_pytest/main.py&quot;, line 247, in _main
  INTERNALERROR&gt;     config.hook.pytest_runtestloop(session=session)
  INTERNALERROR&gt;   File &quot;/usr/local/lib/python3.7/site-packages/pluggy/hooks.py&quot;, line 286, in __call__
  INTERNALERROR&gt;     return self._hookexec(self, self.get_hookimpls(), kwargs)
  INTERNALERROR&gt;   File &quot;/usr/local/lib/python3.7/site-packages/pluggy/manager.py&quot;, line 93, in _hookexec
  INTERNALERROR&gt;     return self._inner_hookexec(hook, methods, kwargs)
  INTERNALERROR&gt;   File &quot;/usr/local/lib/python3.7/site-packages/pluggy/manager.py&quot;, line 87, in &lt;lambda&gt;
  INTERNALERROR&gt;     firstresult=hook.spec.opts.get(&quot;firstresult&quot;) if hook.spec else False,
  INTERNALERROR&gt;   File &quot;/usr/local/lib/python3.7/site-packages/pluggy/callers.py&quot;, line 208, in _multicall
  INTERNALERROR&gt;     return outcome.get_result()
  INTERNALERROR&gt;   File &quot;/usr/local/lib/python3.7/site-packages/pluggy/callers.py&quot;, line 80, in get_result
  INTERNALERROR&gt;     raise ex[1].with_traceback(ex[2])
  INTERNALERROR&gt;   File &quot;/usr/local/lib/python3.7/site-packages/pluggy/callers.py&quot;, line 187, in _multicall
  INTERNALERROR&gt;     res = hook_impl.function(*args)
  INTERNALERROR&gt;   File &quot;/usr/local/lib/python3.7/site-packages/xdist/dsession.py&quot;, line 112, in pytest_runtestloop
  INTERNALERROR&gt;     self.loop_once()
  INTERNALERROR&gt;   File &quot;/usr/local/lib/python3.7/site-packages/xdist/dsession.py&quot;, line 135, in loop_once
  INTERNALERROR&gt;     call(**kwargs)
  INTERNALERROR&gt;   File &quot;/usr/local/lib/python3.7/site-packages/xdist/dsession.py&quot;, line 175, in worker_workerfinished
  INTERNALERROR&gt;     self._active_nodes.remove(node)
  INTERNALERROR&gt; KeyError: &lt;WorkerController gw0&gt;
  </code></pre>
  <p>Thanks in advance for any help!</p>