Comments (3)
Currently no. The reason is that VCR only patches the HTTP code while inside the context manager, so I can't modify HTTP requests outside of that context.
If there is sufficient interest I can look into this, but I think it would involve monkey patching at import time so I'm not too excited about the implementation.
from vcrpy.
As a bystander unfamiliar with the Ruby version, I thought that maybe this feature was to raise an error if using the context manager and the cassette file wasn't present. But I was probably wrong as I've never used the Ruby version. That seems like a useful feature -- is that possible already?
As for disallowing requests when not using the context manager, one could look at using something like this in their tests:
http://pytest.org/latest/monkeypatch.html#example-preventing-requests-from-remote-operations
This is specifically for py.test and requests, but the idea could be extended to use mock and other HTTP libraries, as needed.
from vcrpy.
As a bystander unfamiliar with the Ruby version, I thought that maybe this feature was to raise an error if using the context manager and the cassette file wasn't present.
Sort of. The Ruby version doesn't really have a context manager like VCR.py does, and does all its monkeypatching when importing the package. From the docs:
Usually, HTTP requests made when no cassette is inserted will result in an error
VCR.py's context managers are kind of like Ruby VCR's cassette being inserted.
I thought that maybe this feature was to raise an error if using the context manager and the cassette file wasn't present.
I think this is possible if you use the "none" record mode. If the request hasn't been made before, it will fail with an error. Actually the cassette file can be present as long as it doesn't have the request in it, and it should still fail.
from vcrpy.
Related Issues (20)
- [CORE BUG][Verified Can Replicate] Wrong number of requests recorded under new_episodes mode HOT 3
- 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
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.