1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60
|
from pathlib import Path
def test_interruption_cleanup(testdir, tcp_port):
server_path = Path(__file__).parent.joinpath("server.py").absolute()
testdir.makepyfile(
"""
import sys
import socket
from xprocess import ProcessStarter
def test_servers_start(request, xprocess):
port = %r
server_path = %r
class Starter(ProcessStarter):
terminate_on_interrupt = True
pattern = "started"
args = [sys.executable, server_path, port]
xprocess.ensure("server_test_interrupt", Starter)
raise KeyboardInterrupt
"""
% (tcp_port, str(server_path))
)
result = testdir.runpytest_subprocess()
result.stdout.fnmatch_lines("*KeyboardInterrupt*")
result = testdir.runpytest("--xshow")
result.stdout.no_fnmatch_line("*LIVE*")
def test_interruption_does_not_cleanup(testdir, tcp_port):
server_path = Path(__file__).parent.joinpath("server.py").absolute()
testdir.makepyfile(
"""
import sys
import socket
from xprocess import ProcessStarter
def test_servers_start(request, xprocess):
port = %r
server_path = %r
class Starter(ProcessStarter):
pattern = "started"
args = [sys.executable, server_path, port]
xprocess.ensure("server_test_interrupt_no_terminate", Starter)
raise KeyboardInterrupt
"""
% (tcp_port, str(server_path))
)
result = testdir.runpytest_subprocess()
result.stdout.fnmatch_lines("*KeyboardInterrupt*")
result = testdir.runpytest("--xshow")
result.stdout.fnmatch_lines("*LIVE*")
result = testdir.runpytest("--xkill")
result.stdout.fnmatch_lines("*TERMINATED*")
|