kiwicom/pytest-recording

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

AndreCimander opened this issue · 4 comments

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

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.

@AndreCimander

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

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.

Great to hear that! :)

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