Closed jarhill0 closed 4 years ago
I don't fully understand the necessity for these kinds of hooks.
Right now, all of Betamax's hooks are there to allow modification of the request or response data. Introducing a whole different set of hooks seems like it might confound things a bit.
Right now, all of Betamax's hooks are there to allow modification of the request or response data.
Yes. For our purposes (modifying behavior slightly based on whether a cassette is about to be recorded or about to be played back), having a hook that occurs per-cassette rather than per-request (and before any request) is useful. In case you're interested in reading the relevant commit, it's here, but I suspect that it won't be very interesting or immediately comprehensible.
a whole different set of hooks
I'm only interested in this one particular hook… 😁
In general, I think more hooks makes Betamax more powerful. But perhaps it removes some simplicity.
I'm inclined to make this hook more of a notification style than something that can modify things. What behaviour are you considering modifying?
In my case, I'm not modifying Betamax behavior, though I am reading its state to determine whether the cassette is about to record or about to be played back. In the case that it's about to be played back, we modify the class being tested to select the appropriate authentication scheme. Once the cassette is recorded, the auth scheme doesn't matter, because the cassette will play back correctly either way.
Got it. I think we could probably add a hook or two that basically signal:
A recently merged change in PRAW (which uses Betamax for its integration tests) hacks in an "after init" hook:
source code in PRAW repo
For PRAW's tests, this hook is useful because it triggers at the time
.use_cassette()
is called, which in the case of PRAW's tests signifies that network requests will happen soon but they haven't started yet. This hook allows us to modify the test environment slightly before any requests are made, based on whether a certain cassette has been recorded or not.Rather than having to monkeypatch Betamax, it would be better for PRAW if this hook existed natively in Betamax. Would this be a welcome feature in Betamax? If so, I'll be happy to write the feature.