Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Betamax objects share global configuration #40

Open
jerith opened this issue Sep 18, 2014 · 4 comments
Open

Betamax objects share global configuration #40

jerith opened this issue Sep 18, 2014 · 4 comments

Comments

@jerith
Copy link

jerith commented Sep 18, 2014

All configuration information seems to be shared between all Betamax objects, which means that creating a new instance changes the behaviour of existing objects:

>>> from betamax import Betamax
>>> from requests import Session
>>> bm = Betamax(Session(), cassette_library_dir="1", default_cassette_options={"record_mode": "none"})
>>> print bm.config.cassette_library_dir, bm.config.default_cassette_options["record_mode"]
1 none
>>> bm2 = Betamax(Session(), cassette_library_dir="2", default_cassette_options={"record_mode": "all"})
>>> print bm2.config.cassette_library_dir, bm2.config.default_cassette_options["record_mode"]
2 all
>>> print bm.config.cassette_library_dir, bm.config.default_cassette_options["record_mode"]
2 all

This is both surprising and problematic when one wants to use different recorders for different requests within the same test.

--- Want to back this issue? **[Post a bounty on it!](https://www.bountysource.com/issues/4462489-betamax-objects-share-global-configuration?utm_campaign=plugin&utm_content=tracker%2F198445&utm_medium=issues&utm_source=github)** We accept bounties via [Bountysource](https://www.bountysource.com/?utm_campaign=plugin&utm_content=tracker%2F198445&utm_medium=issues&utm_source=github).
@sigmavirus24
Copy link
Collaborator

It shouldn't be that surprising given that we explicitly mention that the Configuration object is a proxy to global settings and is meant to be used once. The documentation for the Betamax object is currently out of date (in suggesting you should pass default_cassette_options). Further, one goal of this library was to be as similar to the original VCR as possible which is why we encourage the practice of calling Betamax.configure() before your tests to configure the library.

I can see the purpose of setting different cassette library directories, so I'll fix that, but I'm also going to deprecate passing a dictionary of default cassette options as well. It doesn't quite belong there. All of those options should either be set once globally, or if they are a per-request issue, should be passed to Betamax#use_cassette. You can, and should be doing this:

bm = Betamax(Session())  # cassette_library_dir optional
bm2 = Betamax(Session())
bm.use_cassette('cassette_name', record='none')
bm.use_cassette('other_cassette_name', record='all')

Granted the documentation for this is also missing.

@jerith
Copy link
Author

jerith commented Sep 18, 2014

Awesome, thanks for the quick response!

Would it be reasonable to use named parameters instead of **kwargs in Betamax#use_cassette so it's easier to see what's available?

@sigmavirus24
Copy link
Collaborator

Would it be reasonable to use named parameters instead of **kwargs in Betamax#use_cassette so it's easier to see what's available?

Oh damn, I never responded. I'm totally okay with that. I was using **kwargs because it was easy.

@sigmavirus24
Copy link
Collaborator

FWIW, I'm considering a 1.0 in which each betamax.Betamax instance gets a Configuration object that, once set-up, is immutable.

@sigmavirus24 sigmavirus24 modified the milestone: 1.0.0 Jul 16, 2015
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants