File: test_interruption_clean_up.py

package info (click to toggle)
python-pytest-xprocess 0.22.2-2
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 288 kB
  • sloc: python: 698; makefile: 35; sh: 10
file content (60 lines) | stat: -rw-r--r-- 1,841 bytes parent folder | download | duplicates (2)
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*")