kevlened / pytest-parallel

A pytest plugin for parallel and concurrent testing
https://github.com/browsertron/pytest-parallel/issues/104#issuecomment-1293941066
MIT License
313 stars 60 forks source link

'--workers 2' raise error when working with pytest5.x #36

Closed AndyFoolish closed 2 years ago

AndyFoolish commented 5 years ago

Traceback (most recent call last): File "run_case.py", line 37, in ret = pytest.main() File "/project/venv/lib/python3.6/site-packages/_pytest/config/init.py", line 74, in main return config.hook.pytest_cmdline_main(config=config) File "/project/venv/lib/python3.6/site-packages/pluggy/hooks.py", line 289, in call return self._hookexec(self, self.get_hookimpls(), kwargs) File "/project/venv/lib/python3.6/site-packages/pluggy/manager.py", line 87, in _hookexec return self._inner_hookexec(hook, methods, kwargs) File "/project/venv/lib/python3.6/site-packages/pluggy/manager.py", line 81, in firstresult=hook.spec.opts.get("firstresult") if hook.spec else False, File "/project/venv/lib/python3.6/site-packages/pluggy/callers.py", line 208, in _multicall return outcome.get_result() File "/project/venv/lib/python3.6/site-packages/pluggy/callers.py", line 80, in get_result raise ex[1].with_traceback(ex[2]) File "/project/venv/lib/python3.6/site-packages/pluggy/callers.py", line 187, in _multicall res = hook_impl.function(*args) File "/project/venv/lib/python3.6/site-packages/_pytest/main.py", line 250, in pytest_cmdline_main return wrap_session(config, _main) File "/project/venv/lib/python3.6/site-packages/_pytest/main.py", line 243, in wrap_session session=session, exitstatus=session.exitstatus File "/project/venv/lib/python3.6/site-packages/pluggy/hooks.py", line 289, in call return self._hookexec(self, self.get_hookimpls(), kwargs) File "/project/venv/lib/python3.6/site-packages/pluggy/manager.py", line 87, in _hookexec return self._inner_hookexec(hook, methods, kwargs) File "/project/venv/lib/python3.6/site-packages/pluggy/manager.py", line 81, in firstresult=hook.spec.opts.get("firstresult") if hook.spec else False, File "/project/venv/lib/python3.6/site-packages/pluggy/callers.py", line 203, in _multicall gen.send(outcome) File "/project/venv/lib/python3.6/site-packages/_pytest/terminal.py", line 665, in pytest_sessionfinish self.summary_stats() File "/project/venv/lib/python3.6/site-packages/_pytest/terminal.py", line 863, in summary_stats (line, color) = build_summary_stats_line(self.stats) File "/project/venv/lib/python3.6/site-packages/_pytest/terminal.py", line 1014, in build_summary_stats_line for foundtype in stats: File "", line 2, in __getitem_\ File "/usr/local/Cellar/python/3.6.5/Frameworks/Python.framework/Versions/3.6/lib/python3.6/multiprocessing/managers.py", line 772, in _callmethod raise convert_to_error(kind, result) KeyError: 0

heibanke commented 4 years ago

i got the same error.

blueyed commented 4 years ago

It works with 5.2.4.dev6+ge856638ba for me (master), but fails on the "features" branch:

  File "…/Vcs/pytest/src/_pytest/terminal.py", line 468, in pytest_runtest_logfinish
    main_color, _ = _get_main_color(self.stats)
  File "…/Vcs/pytest/src/_pytest/terminal.py", line 1102, in _get_main_color
    for found_type in stats:
  File "<string>", line 2, in __iter__
  File "/usr/lib/python3.7/multiprocessing/managers.py", line 825, in _callmethod
    proxytype = self._manager._registry[token.typeid][-1]
AttributeError: 'NoneType' object has no attribute '_registry'

The following patch for pytest fixes it:

diff --git i/src/_pytest/terminal.py w/src/_pytest/terminal.py
index 40e12e406..e88545eca 100644
--- i/src/_pytest/terminal.py
+++ w/src/_pytest/terminal.py
@@ -1099,7 +1099,7 @@ def _get_main_color(stats) -> Tuple[str, List[str]]:
         "failed passed skipped deselected xfailed xpassed warnings error".split()
     )
     unknown_type_seen = False
-    for found_type in stats:
+    for found_type in stats.keys():
         if found_type not in known_types:
             if found_type:  # setup/teardown reports have an empty key, ignore them
                 known_types.append(found_type)

I have some WIP in that area already, but pytest-parallel should handle iteration of stats probably, if it's easy.

Related code there: https://github.com/browsertron/pytest-parallel/blob/eb851777d354ba79d26d9b088bc1c22a8d44720b/pytest_parallel/__init__.py#L254-L269 (haven't looked at it really)

blueyed commented 4 years ago

JFI: the error I've posted happens when run in the subprocess, and starts to happen with pytest 5.3.0.

I am not sure why the original report is a problem / how it is triggered, since this should run in the main process.

https://github.com/pytest-dev/pytest/pull/6261 however should fix both (at least the one from me).

blueyed commented 4 years ago

@AndyFoolish Is this fixed with the latest release for you?

HardNorth commented 2 years ago

@azmeuk Please consider closing this out. It is seen by the discussion that the issue is related to pytest itself. And I also tested on my synthetic suite all major pytest versions starting from 5.2 till 7.1 without any issues. I would closed this until someone provide a reproducible example.