Comments (8)
And when running with wifi connected, I'm almost certain that both times the request was still made to the servers!
from vcrpy.
The integration test here fails when run without a wifi connection.
from vcrpy.
Note also that the integration test for testing POST requests is for some reason using redirect.yaml
. I suspect this is a copy-and-paste error!
# In https://github.com/kevin1024/vcrpy/blob/master/tests/integration/test_requests.py...
def test_post(tmpdir, scheme):
'''Ensure that we can post and cache the results'''
data = {'key1': 'value1', 'key2': 'value2'}
url = scheme + '://httpbin.org/post'
with vcr.use_cassette(str(tmpdir.join('redirect.yaml'))) as cass:
...
from vcrpy.
I run this test the first time with my wifi connected and a second time with my wifi disconnected.
I'm unable to reproduce this problem. I ran your sample code once with the wifi on, and it produced the yaml file, and the second time with wifi off, and the test still passed.
Was fixtures/foobar.yaml created when you ran the test the first time?
Note also that the integration test for testing POST requests is for some reason using redirect.yaml.
Yeah, it's a copy/paste error, though it doesn't actually matter since those files are in a tmpdir specifically created just for that one test run. I'll fix that though, thanks for the heads-up.
The integration test here fails when run without a wifi connection.
Yes, the VCR test suite requires an internet connection (except for the unit tests, which don't make network requests). I decided to do this so I can test the creation of cassettes and to ensure that the connection correctly passes through to httplib if there is no cassette (too bad I can't use VCR to test VCR!)
from vcrpy.
Hey @kevin1024, thanks for responding promptly.
Apologies! The code I posted really doesn't produce the problem. I found a more clear way to reproduce the problem and updated the issue description:
# This test SUCCEEDS
def test_vcr_works_with_requests():
with vcr.use_cassette('fixtures/test_vcr/foobar.yaml'):
r = requests.post("http://requestb.in/179gbs61")
# This test FAILS
def test_vcr_works_with_requests_with_file_upload():
with vcr.use_cassette('fixtures/test_vcr/foobar-file-upload.yaml'):
with open (os.path.abspath('lolcat.jpg')) as f:
r = requests.post("http://requestb.in/179gbs61", files={'photo':f})
Yes, the VCR test suite requires an internet connection
Well I hope VCR tests in general do not require it — although we're always connected nowadays it's a matter of principle that tests should pass without it!
from vcrpy.
So I'm doing some detective work around this because I really want to get this working.
The relevant part that discriminates the two requests.post
calls is:
https://github.com/kennethreitz/requests/blob/master/requests/models.py#L404
I'm no expert, but @kevin1024 you may be able to spot why VCR might be tripping up here.
from vcrpy.
Okay, with some Python debugging I found that this really is a simple case of the vcr.Request
not being looked up in the requests
OrderedDict
correctly. Though the cassette strictly speaking contains the request, when performing the lookup the hashes mustn't have matched for some reason. I'll look into this further.
from vcrpy.
Closing since #29 and #30 address this same issue.
from vcrpy.
Related Issues (20)
- autodoc fails for API documentation
- Integration tests fail with httpbin 0.10.0 HOT 3
- AIOHTTP not recording json body HOT 1
- How to run tests HOT 2
- [BUG] Doesn't work for URL's beginning with www.
- How is vcrpy importing from a parent directory in a test file HOT 1
- AttributeError: 'VCRHTTPResponse' object has no attribute 'json' HOT 2
- Add type annotations
- Backport patch to fix test failures with Python 3.12: AttributeError: type object 'VCRHTTPConnection[…]' has no attribute 'debuglevel' HOT 1
- [Duplicate of #719?] Upgrading to VCR.py that uses urllib3 v2+ causes string decoding problems with requests HOT 2
- 🛠️ Custom Persister HOT 1
- Release 6.0.0 to allow users to update to Python 3.12? HOT 20
- `TypeError: cannot pickle 'generator' object` with urllib 2.1.0, no error with urllib 1.26.18
- [Question] Would it make sense to support glob in `filter_headers`
- VCRHTTPResponse should have a `release_conn()` method
- record creation failed when using async HOT 2
- 'VCRHTTPConnection/...' has no attribute 'debuglevel'. Did you mean: 'set_debuglevel'
- Bug Report: Installation Failure of vcrpy>=5.0.0 in Conda Environment HOT 1
- Exception httpx.ResponseNotRead thrown randomly when using cassettes HOT 1
- Httpx Response content is not set/read, causing JSON parsing errors
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from vcrpy.