1
0
mirror of https://github.com/kevin1024/vcrpy.git synced 2025-12-09 01:03:24 +00:00

docs/usage.rst: Fix assertions

Symptom was:
> Traceback (most recent call last):
>   File "/tmp/tmp.kJAKlLngAX/foo.py", line 6, in <module>
>     assert 'Example domains' in response
> TypeError: a bytes-like object is required, not 'str'
This commit is contained in:
Sebastian Pipping
2023-06-16 14:04:42 +02:00
committed by Jair Henrique
parent 42848285a0
commit bd112a2385

View File

@@ -8,7 +8,7 @@ Usage
with vcr.use_cassette('fixtures/vcr_cassettes/synopsis.yaml'): with vcr.use_cassette('fixtures/vcr_cassettes/synopsis.yaml'):
response = urllib.request.urlopen('http://www.iana.org/domains/reserved').read() response = urllib.request.urlopen('http://www.iana.org/domains/reserved').read()
assert 'Example domains' in response assert b'Example domains' in response
Run this test once, and VCR.py will record the HTTP request to Run this test once, and VCR.py will record the HTTP request to
``fixtures/vcr_cassettes/synopsis.yaml``. Run it again, and VCR.py will ``fixtures/vcr_cassettes/synopsis.yaml``. Run it again, and VCR.py will
@@ -26,7 +26,7 @@ look like this:
@vcr.use_cassette('fixtures/vcr_cassettes/synopsis.yaml') @vcr.use_cassette('fixtures/vcr_cassettes/synopsis.yaml')
def test_iana(): def test_iana():
response = urllib.request.urlopen('http://www.iana.org/domains/reserved').read() response = urllib.request.urlopen('http://www.iana.org/domains/reserved').read()
assert 'Example domains' in response assert b'Example domains' in response
When using the decorator version of ``use_cassette``, it is possible to When using the decorator version of ``use_cassette``, it is possible to
omit the path to the cassette file. omit the path to the cassette file.
@@ -36,7 +36,7 @@ omit the path to the cassette file.
@vcr.use_cassette() @vcr.use_cassette()
def test_iana(): def test_iana():
response = urllib.request.urlopen('http://www.iana.org/domains/reserved').read() response = urllib.request.urlopen('http://www.iana.org/domains/reserved').read()
assert 'Example domains' in response assert b'Example domains' in response
In this case, the cassette file will be given the same name as the test In this case, the cassette file will be given the same name as the test
function, and it will be placed in the same directory as the file in function, and it will be placed in the same directory as the file in