-
-
Notifications
You must be signed in to change notification settings - Fork 16
/
Copy pathtest_pytest_responses.py
58 lines (41 loc) · 1.43 KB
/
test_pytest_responses.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
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
from __future__ import (
absolute_import, print_function, division, unicode_literals
)
import requests
import responses
import pytest
from requests.exceptions import ConnectionError
pytest_plugins = str('pytester')
@pytest.mark.withoutresponses
def test_disabled():
with pytest.raises(ConnectionError):
requests.get('http://responses.invalid')
assert len(responses.calls) == 0
def test_enabled():
with pytest.raises(ConnectionError):
requests.get('http://responses.invalid')
assert len(responses.calls) == 1
def test_marker(testdir):
result = testdir.runpytest('--markers')
assert '@pytest.mark.withoutresponses' in result.stdout.str()
class TestReset:
"""
Ensure that the callback registered in `test_1` is cleaned up before
`test_2`.
"""
def test_1(self):
responses.add(responses.GET, 'http://responses.invalid', json=1)
assert requests.get('http://responses.invalid').json() == 1
def test_2(self):
responses.add(responses.GET, 'http://responses.invalid', json=2)
assert requests.get('http://responses.invalid').json() == 2
class TestSkip:
"""
Ensure that we don't choke on skipped tests.
"""
@pytest.mark.skip
def test_1(self):
assert 2 + 2 == 5
def test_2(self):
responses.add(responses.GET, 'http://responses.invalid', json='foo')
assert requests.get('http://responses.invalid').json() == 'foo'