Skip to content

Instantly share code, notes, and snippets.

@jarhill0
Last active January 13, 2020 01:08
Show Gist options
  • Save jarhill0/72dd9e43d29f2b47d846edc263a0a7f2 to your computer and use it in GitHub Desktop.
Save jarhill0/72dd9e43d29f2b47d846edc263a0a7f2 to your computer and use it in GitHub Desktop.
Demonstrating use of new cassette load/eject hooks in Betamax
from betamax import Betamax
from requests import Session
def before(cassette): print('cassette created.')
def after(cassette): print('cassette destroyed')
session = Session()
recorder = Betamax(session, cassette_library_dir='test cassettes')
with recorder.configure() as config:
config.after_start(callback=before)
config.before_stop(callback=after)
with recorder.use_cassette('My test cassette'):
print('in with block')
print(session.get('https://github.com'))
print('about to exit with block')
cassette created.
in with block
<Response [200]>
about to exit with block
cassette destroyed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment