mirror of
https://github.com/kevin1024/vcrpy.git
synced 2025-12-08 16:53:23 +00:00
Fix log format bug
`{}` is not a valid placeholder in log formatting.
This commit is contained in:
@@ -1,4 +1,5 @@
|
||||
import contextlib
|
||||
import logging
|
||||
|
||||
import pytest
|
||||
asyncio = pytest.importorskip("asyncio")
|
||||
@@ -112,7 +113,8 @@ def test_stream(tmpdir, scheme):
|
||||
|
||||
|
||||
@pytest.mark.parametrize('body', ['data', 'json'])
|
||||
def test_post(tmpdir, scheme, body):
|
||||
def test_post(tmpdir, scheme, body, caplog):
|
||||
caplog.set_level(logging.INFO)
|
||||
data = {'key1': 'value1', 'key2': 'value2'}
|
||||
url = scheme + '://httpbin.org/post'
|
||||
with vcr.use_cassette(str(tmpdir.join('post.yaml'))):
|
||||
@@ -125,6 +127,16 @@ def test_post(tmpdir, scheme, body):
|
||||
assert cassette_response_json == response_json
|
||||
assert cassette.play_count == 1
|
||||
|
||||
assert next(
|
||||
(
|
||||
log
|
||||
for log in caplog.records
|
||||
if log.getMessage()
|
||||
== '<Request (POST) {}> not in cassette, sending to real server'.format(url)
|
||||
),
|
||||
None,
|
||||
), 'Log message not found.'
|
||||
|
||||
|
||||
def test_params(tmpdir, scheme):
|
||||
url = scheme + '://httpbin.org/get'
|
||||
|
||||
@@ -137,7 +137,7 @@ def vcr_request(cassette, real_request):
|
||||
response.close()
|
||||
return response
|
||||
|
||||
log.info("{} not in cassette, sending to real server", vcr_request)
|
||||
log.info('%s not in cassette, sending to real server', vcr_request)
|
||||
|
||||
response = await real_request(self, method, url, **kwargs) # NOQA: E999
|
||||
await record_responses(cassette, vcr_request, response)
|
||||
|
||||
Reference in New Issue
Block a user