Python源码示例:responses.stop()
示例1
def mock_request():
with open(path.join(path.dirname(path.realpath(__file__)),
'fake_response.json')) as f:
fake_response = json.load(f)
responses.add(
responses.GET,
url=("https://www.bing.com/HPImageArchive.aspx?format"
"=js&idx=0&n=1&nc=1409879295618&pid=hp"),
json=fake_response,
status=200,
match_querystring=True
)
responses.add(
responses.GET,
url=('https://www.bing.com/th?id=OHR.OldManWhiskers_ZH-CN9321160932_'
'1920x1080.jpg&rf=LaDigue_1920x1080.jpg&pid=hp'),
status=200,
body='Hello, world'
)
responses.start()
yield responses
responses.stop()
示例2
def pytest_runtest_teardown(item):
if not get_withoutresponses_marker(item):
try:
responses_.stop()
responses_.reset()
except RuntimeError:
# patcher was already uninstalled and responses doesnt let us
# force maintain it
pass
示例3
def mock_api():
with open(path.join(ROOT, 'signin.html'), encoding='utf-8') as f:
mock_signin_body = f.read()
responses.add(responses.POST, 'https://www.v2ex.com/signin',
body=mock_signin_body)
responses.add(responses.GET, 'https://www.v2ex.com/signin',
body=mock_signin_body)
with open(path.join(ROOT, 'once.html'), encoding='utf-8') as f:
mock_once_body = f.read()
responses.add(responses.GET,
'https://www.v2ex.com/mission/daily/redeem?once=51947',
body=mock_once_body)
with open(path.join(ROOT, 'balance.html'), encoding='utf-8') as f:
mock_balance_body = f.read()
responses.add(responses.GET, 'https://www.v2ex.com/balance',
body=mock_balance_body)
with open(path.join(ROOT, 'mission.html'), encoding='utf-8') as f:
mock_mission_body = f.read()
responses.add(responses.GET, 'https://www.v2ex.com/mission/daily',
body=mock_mission_body)
responses.start()
yield responses
responses.stop()
示例4
def response_fixture_factory(url, data=None, status=200):
@pytest.yield_fixture
def fixture():
responses.add(
responses.POST,
url,
status=status,
body=json.dumps(data or {}),
content_type='application/json',
)
responses.start()
yield responses
responses.stop()
responses.reset()
return fixture
示例5
def tearDown(self):
await super(HollowmanAppTest, self).tearDown()
responses.stop()
示例6
def tearDown(self):
await super(AuthenticationTest, self).tearDown()
responses.stop()
示例7
def tearDown(self):
responses.stop()
示例8
def tearDown(self):
responses.stop()
# todo: debater nome request_app e app <- app fica ambíguo
示例9
def tearDown(self):
self.mock.stop()
responses.stop()
super(AddVersionedListsTest, self).tearDown()
示例10
def tearDown(self):
self.mock.stop()
responses.stop()
super(S3SourceListsTest, self).tearDown()
示例11
def teardown_method(self, method):
responses.reset()
responses.stop()