Comments (6)
For scope="module" it also does not record requests/responses done in fixtures.
from pytest-recording.
Hi! Unfortunately I don’t have much bandwidth to implement it myself, but will be happy to provide guidance and review a PR
from pytest-recording.
What could be done to make pytest-recording
work for fixtures? I'd like to use this library for all VCR so we can ensure headers are filtered by default, but we can't currently do that if it doesn't support recording for session
-scoped fixtures.
from pytest-recording.
@Stranger6667, I'd be happy to submit a PR to support marking fixtures in this library. Could you please point me in the right direction or any known blockers?
from pytest-recording.
Hi everybody! Sorry for the delay.
I think that the way to approach this is to use the logic from the _vcr.py
module with fixtures of non-"function" scope. For example, make each "session" fixture depend on a separate "vcr_session" fixture that works similarly to vcr. I.e. opens a context manager that records a cassette.
Though, not sure about configuring such a cassette writer - all the cassette naming & other stuff comes either from higher-level fixtures or pytest marks. The latter don't work on fixtures as far as I can tell :( However, there are module-level marks, so it may be used for recording cassettes inside module-level fixtures.
Here is an idea: Make a session-level fixture that works similarly to the vcr
one and also is autouse=True
, but can only access session-level configuration (e.g. session-level vcr_config
fixture). Then disable it inside the vcr
fixture, so it is not recoding calls during the test.
Recording module-level fixtures adds an extra layer here but could be done similarly implementation-wise: no access to higher-level configs & disabling the session-level fixture inside.
Important note: We really need to isolate cassettes from different levels during execution. As VCR is mocking transports, I'd assume it is replacing globally-available functions, so cassettes will interfere with each other. So, it might require some bookkeeping with enabling/disabling different cassettes properly.
Those are my current thoughts on this problem, and I didn't check if this approach will actually work (I assume it should). Let me know if you'd like me to elaborate.
from pytest-recording.
Hi @Stranger6667, is there any update on this? I would be really nice to be able to use vcr in fixtures.
from pytest-recording.
Related Issues (20)
- `@pytest.mark.vcr(before_record_response=...)` behaves differently when recording and playing back HOT 1
- How to check if a cassette is playing back?
- failing tests on fresh repository clone HOT 1
- Allow using `pytest-recording` with a command-line flag only HOT 1
- No cassettes found on vcrpy==5.0.0 release. Works with 4.* HOT 10
- [FEATURE] Disable Recording from Fixture HOT 1
- Cannot record when use GitPython HOT 2
- [BUG] tests/test_blocking_network.py::test_pycurl* failures due to whitespace (?) HOT 4
- [BUG] tests/test_blocking_network.py::test_block_network_with_allowed_hosts fail with no network (does not block DNS requests?))
- [FEATURE] usage for doctests HOT 6
- [FEATURE] Support pytest config file options
- [FEATURE] Delete casette if test fails when running with --record-mode=once HOT 1
- [BUG] having this plugin enabled breaks Intellij Idea failed test reports
- Is there a no decorator mode? HOT 2
- Conflict with requests-ntlm ('NoneType' object has no attribute 'raw') HOT 2
- Dependency Dashboard
- Filter sensitive data from response/how to use `before_record_response`? HOT 3
- [FEATURE] Add Python 3.10 support
- [FEATURE] Drop Python 3.5 / 3.6 support HOT 1
- Save responses to different cassette files depending on host
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 pytest-recording.