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

Issue with betamax not recording requests within unconsumed generators #131

Open
guyzmo opened this issue Jan 31, 2017 · 6 comments
Open

Comments

@guyzmo
Copy link

guyzmo commented Jan 31, 2017

cf sigmavirus24/github3.py#679

tl;dr

I have setup tests with helpers such as:

class TestTheThing:
    def helper_method(self, arg1, arg2, arg3):
        with self.recorder.use_cassette("cassette_name"):
            thing_to_test = self.thing_containing_what_to_test(arg1)
            return self.thing_to_test.iter_items(arg2, arg3)

    def test_with_some_options(self):
        contents = self.helper_method("a", "b", "c")
        assert list(contents) == ['foobar']

in the example above, I'm returning a generator from the helper method. So when in the test I'm transforming it into a list, the iterator runs the generator AFTER the with statement has been exited.

The fix is simply to run the generator within the with block context.

possible actions

  • keep it as is for future readers
  • make it as part of a "stupid mistake" FAQ?
  • add some parameter to betamax to help debug that class of mistakes faster
--- Want to back this issue? **[Post a bounty on it!](https://www.bountysource.com/issues/41524048-issue-with-betamax-not-recording-requests-within-unconsumed-generators?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).
@guyzmo guyzmo closed this as completed Jan 31, 2017
@guyzmo guyzmo changed the title Issue with betamax not recording iter_xxx generator requests Issue with betamax not recording requests within iter_xxx generator Jan 31, 2017
@sigmavirus24 sigmavirus24 changed the title Issue with betamax not recording requests within iter_xxx generator Issue with betamax not recording requests within unconsumed generators Feb 1, 2017
@sigmavirus24
Copy link
Collaborator

sigmavirus24 commented Feb 1, 2017

add some parameter to betamax to help debug that class of mistakes faster

So the problem is that Betamax replaces the original cassettesadapters. There's no parameter we can provide that would warn someone that they're making a call to a generator or anything like that. We're just not that smart.

make it as part of a "stupid mistake" FAQ?

I wouldn't call it "stupid mistake". I'd label it "common missteps".

keep it as is for future readers

I'm not sure what "it" is here.

@sigmavirus24 sigmavirus24 reopened this Feb 1, 2017
@guyzmo
Copy link
Author

guyzmo commented Feb 1, 2017

So the problem is that Betamax replaces the original cassettes. There's no parameter we can provide that would warn someone that they're making a call to a generator or anything like that. We're just not that smart.

Of course not, but I could imagine that a global config option, that adds verbosity to betamax so that within a test context, more output could be thrown at the user:

  • when betamax is hijacking the request (a log point in enter/exit)
  • when the user is doing a call to send a request outside of betamax context make a log point

maybe would it be possible to catch -vv value of py.test and do that at a given increased verbose level?

I'm not sure what "it" is here.

it is just as an issue in the tracker.

@sigmavirus24
Copy link
Collaborator

maybe would it be possible to catch -vv value of py.test and do that at a given increased verbose level?

That's not possible without looking at sys.argv directly and having to check for both py.test and the verbose options (which is kind of gross).

Further, Betamax aims to be test framework independent. We ship a pytest fixture, but we also ship fixtures for other popular testing frameworks too. I'm asking in #pylib on Freenode IRC about how a library might provide extra debugging information along the way. I'll report back what I'm told.

@sigmavirus24
Copy link
Collaborator

@hroncok for what it's worth, I never received any help in #pylib so feel free to either close this or write some documentation about it. I think it's a great idea to mention common mistakes like this in the documentation but I lost track of this when I tried to rewrite the documentation a while back.

@hroncok
Copy link
Member

hroncok commented Oct 28, 2017

Let's document this then. "Common mistakes" section sounds great. @guyzmo are you willing to send a PR?

@guyzmo
Copy link
Author

guyzmo commented Oct 30, 2017

I can do that, though please point me out which file and where you want the section to be included (basically a file#line github URL).

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

3 participants