Closed kratsg closed 5 years ago
We don't inherently support this.
You can't monkey-patch every Session ever created today with Betamax, nor is that something I'd really want in the core library. Without understanding your command-line better, you might be able to do --use-cassette
, detect that and pass a session
into listinstitutions
that you use instead of core.Session()
which has been Betamax-ified.
Otherwise, you could have a function that returns a session core.make_session()
that checks env-vars or whatever else to determine if you're using betamax and does the right things.
Great, thanks for the response @sigmavirus24 . I suspected as much (un)fortunately.
Let's suppose that we wish to have full coverage of tests. Imagine that we have something like
test_institution.py
which contains a test like the following:and this test works perfectly, where
class mypackage.core.Session(requests.Session)
exists and is aSession
class for the package that inheritsrequests.Session
so it plays nicely with betamax. This is great.Now imagine we have
test_scripts.py
which contains the followingwhere the
commandline.py
looks likeHow can we inject betamax into the
Session
to pick up the saved cassette when the test runs? Is this possible with current betamax? I suspect not.One idea I had is to use environment variables / command line arguments set as part of testing that enable/disable betamax so that
commandline.py
manually injects betamax for us. E.G. something likeand then just inject betamax in there correctly. Am I doing my logic wrong? I would like to be able to test/cover the CLI scripts in the package.