File: failure_demo.py

package info (click to toggle)
python-pytest-timeout 2.3.1-2
  • links: PTS, VCS
  • area: main
  • in suites: sid
  • size: 244 kB
  • sloc: python: 691; makefile: 8; sh: 4
file content (37 lines) | stat: -rw-r--r-- 681 bytes parent folder | download | duplicates (3)
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
"""Demonstration of timeout failures using pytest_timeout.

To use this demo, invoke pytest on it::

   pytest failure_demo.py
"""
import threading
import time

import pytest


def sleep(s):
    """Sleep for a while, possibly triggering a timeout.

    Also adds another function on the stack showing off the stack.
    """
    # Separate function to demonstrate nested calls
    time.sleep(s)


@pytest.mark.timeout(1)
def test_simple():
    """Basic timeout demonstration."""
    sleep(2)


def _run():
    sleep(2)


@pytest.mark.timeout(1)
def test_thread():
    """Timeout when multiple threads are running."""
    t = threading.Thread(target=_run)
    t.start()
    sleep(2)