pytest-dev / pytest-xdist

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

xdist master freezes if socketserver worker calls pytest.exit() #521

Open cielavenir opened 4 years ago

cielavenir commented 4 years ago
import pytest

def test_a():
    pass

def test_b():
    pytest.exit('system state unrecoverable, destroy pytest session.')
root@0fa7f92c43b4:~# pytest -d --tx socket=localhost:8888 test_exit.py --rsyncdir=. # socketserver
==================================================================================== test session starts =====================================================================================
platform linux2 -- Python 2.7.13, pytest-4.6.9, py-1.8.1, pluggy-0.13.1
rootdir: /root
plugins: xdist-1.31.0, forked-1.1.3
gw0 [2]
.[gw0] node down: keyboard-interrupt
f
replacing crashed worker gw0
^C ### pytest freezes until I input Ctrl+C
========================================================================================== FAILURES ==========================================================================================
_____________________________________________________________________________________ root/test_exit.py ______________________________________________________________________________________
[gw0] linux2 -- Python 2.7.13 /usr/bin/python
worker 'gw0' crashed while running 'root/test_exit.py::test_b'
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! KeyboardInterrupt !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
/usr/local/lib/python2.7/dist-packages/execnet/gateway_socket.py:28: KeyboardInterrupt
(to show a full traceback on KeyboardInterrupt use --fulltrace)
============================================================================= 1 failed, 1 passed in 2.58 seconds =============================================================================

root@0fa7f92c43b4:~# pytest -d --tx ssh=localhost test_exit.py --rsyncdir=. # ssh
==================================================================================== test session starts =====================================================================================
platform linux2 -- Python 2.7.13, pytest-4.6.9, py-1.8.1, pluggy-0.13.1
rootdir: /root
plugins: xdist-1.31.0, forked-1.1.3
gw0 [2]
.[gw0] node down: keyboard-interrupt
f
replacing crashed worker gw0
gw1 C  
========================================================================================== FAILURES ==========================================================================================
_____________________________________________________________________________________ root/test_exit.py ______________________________________________________________________________________
[gw0] linux2 -- Python 2.7.13 /usr/bin/python
worker 'gw0' crashed while running 'root/test_exit.py::test_b'
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! Interrupted: <WorkerController gw0> received keyboard-interrupt !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
============================================================================= 1 failed, 1 passed in 1.08 seconds =============================================================================
cielavenir commented 4 years ago

It seems that using pytest.exit(returncode=1) works for our purpose.