-
Notifications
You must be signed in to change notification settings - Fork 264
/
test_utils.py
37 lines (31 loc) · 974 Bytes
/
test_utils.py
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
from unittest import SkipTest, mock
from freezegun import api
from tests import utils
try:
reload
except NameError:
try:
from importlib import reload
except ImportError:
from imp import reload
@mock.patch('platform.python_implementation', lambda: 'CPython')
def test_should_not_skip_cpython():
reload(api)
reload(utils)
function_mock = mock.MagicMock(__name__='function')
try:
utils.cpython_only(function_mock)()
except SkipTest:
raise AssertionError("Test was skipped in CPython")
assert function_mock.called
@mock.patch('platform.python_implementation', lambda: 'not-CPython')
def test_should_skip_non_cpython():
reload(api)
reload(utils)
function_mock = mock.MagicMock(__name__='function', skipped=False)
try:
utils.cpython_only(function_mock)()
except SkipTest:
function_mock.skipped = True
assert not function_mock.called
assert function_mock.skipped