-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtests.py
More file actions
41 lines (28 loc) · 680 Bytes
/
tests.py
File metadata and controls
41 lines (28 loc) · 680 Bytes
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
from time import sleep
import sys
import pytest
from kill_timeout import kill_timeout, TimeoutError as KillTimeoutError
@kill_timeout(0.1)
def f(s):
sleep(s)
return 1
def test_simple():
assert f(0.01) == 1
def test_timeout():
with pytest.raises(KillTimeoutError):
f(0.2)
with pytest.raises(TimeoutError):
f(0.2)
@kill_timeout(0.5)
def f2():
1 / 0
def test_exception():
with pytest.raises(ZeroDivisionError):
f2()
try:
f2()
except ZeroDivisionError:
_, _, tb = sys.exc_info()
while tb.tb_next is not None:
tb = tb.tb_next
assert tb.tb_frame.f_code.co_name == 'f2'