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

[BUG] record_mode set via vcr_config fixture and marker not honored by block_network #68

Closed
AndreCimander opened this issue Jul 8, 2021 · 4 comments · Fixed by #71
Closed

Comments

@AndreCimander
Copy link
Contributor

AndreCimander commented Jul 8, 2021

Describe the bug
Setting the record_mode via config fixture nor marker is not honored by block_network. The record_mode variable in block_network is still in default state "none".

To Reproduce

import pytest
import requests


@pytest.fixture(autouse=True)
def vcr_config():
    return {
        "filter_headers": ["authorization"],
        "ignore_localhost": True,
        "record_mode": "once",
    }


@pytest.mark.vcr()
@pytest.mark.block_network(record_mode="once")
def test_request():
    requests.get("https://google.com")

Expected behavior
Shouldn't raise a RuntimeError since we are supposed to be recording.

Environment (please complete the following information):

  • OS: Linux(Manjaro)
  • Python version: 3.8.7
  • pytest-recording version: 0.11.0
  • pytest version: 6.2.4
@Stranger6667
Copy link
Collaborator

Hi,

Thank you for your detailed report!

I think that there are two related things.

First, the block_network mark is not checked for input arguments - at this point, it should accept only allowed_hosts, nothing else. I missed that originally, but it will be nice to check the input arguments (and for the vcr mark as well to avoid typos)

Second, the record_mode option is indeed ignored when it comes from the vcr_config fixture or the vcr mark. Network blocking is only tested together with the --record-mode CLI option.

@Stranger6667
Copy link
Collaborator

@AndreCimander

The fix is released in 0.12.0; let me know if the fix solves your use case :)

@AndreCimander
Copy link
Contributor Author

AndreCimander commented Jul 9, 2021

Works like a charm, thank you for the quick reaction and fix! 👍

Already planned to vendor a custom block_network as a quickfix(aka the cobblestones to hell 😄 ), which thankfully is now avoided.

@Stranger6667
Copy link
Collaborator

Great to hear that! :)

Feel free to reach out to me if there are any other issues with pytest-recording :)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
2 participants