File: failure_demo.py

package info (click to toggle)
python-pytest-timeout 1.0.0-1.1~bpo8%2B1
  • links: PTS, VCS
  • area: main
  • in suites: jessie-backports
  • size: 152 kB
  • sloc: python: 448; makefile: 16
file content (32 lines) | stat: -rw-r--r-- 456 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
"""Demonstration of timeout failures using pytest_timeout

To use this demo, invoke py.test on it::

   py.test failure_demo.py
"""

import threading
import time

import pytest


def sleep(s):
    # Separate function to demonstrate nested calls
    time.sleep(s)


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


def run():
    sleep(2)


@pytest.mark.timeout(1)
def test_thread():
    t = threading.Thread(target=run)
    t.start()
    sleep(2)