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

[FEATURE] Provide a way to use pytest_recording without pytest.mark.vcr decorator #75

Open
Stranger6667 opened this issue Jul 15, 2021 · 2 comments
Assignees

Comments

@Stranger6667
Copy link
Collaborator

Is your feature request related to a problem? Please describe.
It might be convenient to use _vcr.use_cassette directly for granular control of VCR setup & teardown mechanisms.

Describe the solution you'd like
Create a separate function that will not depend on pytest-related types & expose it as a part of the public API. It might be used by _vcr.use_cassette under the hood (or, likely, _vcr.use_cassette will be renamed to something else, and the new function will take this name).

Additional context
Requested by @selevit

@CharString
Copy link

pytest-vcr has a vcr fixture that gives you the configured VCR object so you can swap cassettes mid-test and test non-safe methods in 'once' recording mode.

def test_content_editing(vcr):
    with vcr.use_cassette('tape 1.yaml'):
        requests.post(...)
        assert request.get(...).json()['title'] == 'default'
    with vcr.use_cassette('tape 2.yaml'):
        request.patch(..., json={'title': 'new'}
        assert request.get(...).json()['title'] == 'new'

@jdputsch
Copy link

jdputsch commented Dec 8, 2022

Along these lines, would find it very useful to do something like this:

@pytest.fixture(scope="module")
def p4_ipv(pi, ipv):
    with vcr.use_cassette("p4_ipv.yaml"):
        ipv = pi.ipv("[email protected]")
    return ipv

Allowing me to use VCR is module or session scope to setup several object that would then be the basis for related sets of tests. Today, I would have to do something like this:

@pytest.mark.vcr()
def test_one():
      with vcr.use_cassette("p4_ipv.yaml"):
           ipv = pi.ipv("[email protected]")
      # now use the ipv object in further code

@pytest.mark.vcr()
def test_two():
      with vcr.use_cassette("p4_ipv.yaml"):
           ipv = pi.ipv("[email protected]")
      # now use the ipv object in further code

Which is less than ideal. I'd like to be able to refactor the common code out into a fixture. The fixture may want to be allowed to be function, module, or session scope.

Thanks,

Jeff.

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