Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

not robust to xdist worker crash #75

Closed
dchudz opened this issue Feb 27, 2022 · 0 comments · Fixed by #76
Closed

not robust to xdist worker crash #75

dchudz opened this issue Feb 27, 2022 · 0 comments · Fixed by #76

Comments

@dchudz
Copy link

dchudz commented Feb 27, 2022

(First: Thank you for making pytest-json-report! This package has been a big help to us, as it's much easier to use than the junit output we used previously, and has important capabilities we were missing from that.)

I'm using xdist, and (for reasons I haven't yet determined) sometimes one of the xdist workers dies with [gw17] node down: Not properly terminated.

Normally xdist is robust to that. For example:

pytest -n 3
==================================================================================================================== test session starts =====================================================================================================================
platform darwin -- Python 3.8.12, pytest-7.0.1, pluggy-1.0.0
sensitiveurl: .*
rootdir: /Users/davidchudzicki/xdist_json_test, configfile: setup.cfg
plugins: xdist-2.5.0, forked-1.4.0, flaky-3.7.0, timeout-2.1.0, html-3.1.1, base-url-1.4.1, ddtrace-0.59.0.dev23+gb0f247a7, json-report-1.4.1, asyncio-0.18.1, variables-1.7.1, repeat-0.9.1, metadata-1.11.0, selenium-2.0.1
asyncio: mode=auto
gw0 [10] / gw1 [10] / gw2 [10]
....[gw0] node down: Not properly terminated
F
replacing crashed worker gw0
gw3 ok / gw1 [10] / gw2 [10]  .....
========================================================================================================================== FAILURES ==========================================================================================================================
__________________________________________________________________________________________________________________ test_crash_one_worker.py __________________________________________________________________________________________________________________
[gw0] darwin -- Python 3.8.12 /Users/davidchudzicki/miniconda3/envs/integration-tests/bin/python
worker 'gw0' crashed while running 'test_crash_one_worker.py::test_crash_one_worker[0]'
================================================================================================================== short test summary info ===================================================================================================================
FAILED test_crash_one_worker.py::test_crash_one_worker[0]
================================================================================================================ 1 failed, 9 passed in 2.10s =================================================================================================================

Note that I have 10 tests, they all ran, and I have results for all of them (1 failed, 9 passed).

However, when used with pytest-json-report I get this:

pytest -n 3 --json-report
==================================================================================================================== test session starts =====================================================================================================================
platform darwin -- Python 3.8.12, pytest-7.0.1, pluggy-1.0.0
sensitiveurl: .*
rootdir: /Users/davidchudzicki/xdist_json_test, configfile: setup.cfg
plugins: xdist-2.5.0, forked-1.4.0, flaky-3.7.0, timeout-2.1.0, html-3.1.1, base-url-1.4.1, ddtrace-0.59.0.dev23+gb0f247a7, json-report-1.4.1, asyncio-0.18.1, variables-1.7.1, repeat-0.9.1, metadata-1.11.0, selenium-2.0.1
asyncio: mode=auto
gw0 [10] / gw1 [10] / gw2 [10]
..[gw0] node down: Not properly terminated
FINTERNALERROR> Traceback (most recent call last):
INTERNALERROR>   File "/Users/davidchudzicki/miniconda3/envs/integration-tests/lib/python3.8/site-packages/_pytest/main.py", line 268, in wrap_session
INTERNALERROR>     session.exitstatus = doit(config, session) or 0
INTERNALERROR>   File "/Users/davidchudzicki/miniconda3/envs/integration-tests/lib/python3.8/site-packages/_pytest/main.py", line 322, in _main
INTERNALERROR>     config.hook.pytest_runtestloop(session=session)
INTERNALERROR>   File "/Users/davidchudzicki/miniconda3/envs/integration-tests/lib/python3.8/site-packages/pluggy/_hooks.py", line 265, in __call__
INTERNALERROR>     return self._hookexec(self.name, self.get_hookimpls(), kwargs, firstresult)
INTERNALERROR>   File "/Users/davidchudzicki/miniconda3/envs/integration-tests/lib/python3.8/site-packages/pluggy/_manager.py", line 80, in _hookexec
INTERNALERROR>     return self._inner_hookexec(hook_name, methods, kwargs, firstresult)
INTERNALERROR>   File "/Users/davidchudzicki/miniconda3/envs/integration-tests/lib/python3.8/site-packages/pluggy/_callers.py", line 60, in _multicall
INTERNALERROR>     return outcome.get_result()
INTERNALERROR>   File "/Users/davidchudzicki/miniconda3/envs/integration-tests/lib/python3.8/site-packages/pluggy/_result.py", line 60, in get_result
INTERNALERROR>     raise ex[1].with_traceback(ex[2])
INTERNALERROR>   File "/Users/davidchudzicki/miniconda3/envs/integration-tests/lib/python3.8/site-packages/pluggy/_callers.py", line 39, in _multicall
INTERNALERROR>     res = hook_impl.function(*args)
INTERNALERROR>   File "/Users/davidchudzicki/miniconda3/envs/integration-tests/lib/python3.8/site-packages/xdist/dsession.py", line 117, in pytest_runtestloop
INTERNALERROR>     self.loop_once()
INTERNALERROR>   File "/Users/davidchudzicki/miniconda3/envs/integration-tests/lib/python3.8/site-packages/xdist/dsession.py", line 140, in loop_once
INTERNALERROR>     call(**kwargs)
INTERNALERROR>   File "/Users/davidchudzicki/miniconda3/envs/integration-tests/lib/python3.8/site-packages/xdist/dsession.py", line 209, in worker_errordown
INTERNALERROR>     self.handle_crashitem(crashitem, node)
INTERNALERROR>   File "/Users/davidchudzicki/miniconda3/envs/integration-tests/lib/python3.8/site-packages/xdist/dsession.py", line 360, in handle_crashitem
INTERNALERROR>     self.config.hook.pytest_runtest_logreport(report=rep)
INTERNALERROR>   File "/Users/davidchudzicki/miniconda3/envs/integration-tests/lib/python3.8/site-packages/pluggy/_hooks.py", line 265, in __call__
INTERNALERROR>     return self._hookexec(self.name, self.get_hookimpls(), kwargs, firstresult)
INTERNALERROR>   File "/Users/davidchudzicki/miniconda3/envs/integration-tests/lib/python3.8/site-packages/pluggy/_manager.py", line 80, in _hookexec
INTERNALERROR>     return self._inner_hookexec(hook_name, methods, kwargs, firstresult)
INTERNALERROR>   File "/Users/davidchudzicki/miniconda3/envs/integration-tests/lib/python3.8/site-packages/pluggy/_callers.py", line 60, in _multicall
INTERNALERROR>     return outcome.get_result()
INTERNALERROR>   File "/Users/davidchudzicki/miniconda3/envs/integration-tests/lib/python3.8/site-packages/pluggy/_result.py", line 60, in get_result
INTERNALERROR>     raise ex[1].with_traceback(ex[2])
INTERNALERROR>   File "/Users/davidchudzicki/miniconda3/envs/integration-tests/lib/python3.8/site-packages/pluggy/_callers.py", line 39, in _multicall
INTERNALERROR>     res = hook_impl.function(*args)
INTERNALERROR>   File "/Users/davidchudzicki/miniconda3/envs/integration-tests/lib/python3.8/site-packages/pytest_jsonreport/plugin.py", line 172, in pytest_runtest_logreport
INTERNALERROR>     metadata = report._json_report_extra.get('metadata')
INTERNALERROR> AttributeError: 'TestReport' object has no attribute '_json_report_extra'

================================================================================================================ 1 failed, 2 passed in 1.34s =================================================================================================================

Note that only 3 tests ran, and I don't have a json report saved. The exit code is also different: 3 for internal error, rather than 1 for failing test.

I can't yet reproduce whatever is causing my crashes in real life, so I'm causing artificial ones for this issue. Here's the test that produces the output above:

import pytest
import os

@pytest.mark.parametrize("n", range(10))
def test_crash_one_worker(n):
    if n == 0:
        pid = os.getpid()
        os.kill(pid, 9)

Relevant versions:

pytest              7.0.1
pytest-json-report  1.4.1
pytest-xdist        2.5.0
@dchudz dchudz changed the title not robust to crashing xdist worker not robust to xdist worker crash Feb 27, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant