Closed cjw296 closed 6 years ago
Looks like I've done this in the past by mocking out the Session class where it's used, but I wonder if there's a better way?
The library doesn't presently provide that functionality.
Can you expand a bit more on the constraints of what you're testing such that you need this functionality?
Looking to test code like this:
def some_func():
session = Session(...)
session.get(...)
I don't think betamax should do that. If you actually really need to do this, than mocking requests.Session
is a way. But if that code is yours, use dependency injection, something like:
def some_func(session=None):
session = session or Session(...)
session.get(...)
@hroncok - we're all entitled to our opinion ;-)
What I mean is that there are techniques how to achieve this kind of thing and implement the support for this inside betamax would be out of it's scope. Do you think that betamax should be able to mock all sessions?
It would be a nice feature to have...
@cjw296 I tend to agree with @hroncok that this isn't really appropriate for the library. The design vision has been pretty consistent. I definitely think a helper for global patching would be valuable to others.
How would I go about using betamax to record requests on all sessions, regardless of where or how they're created?