kiwicom / pytest-recording

A pytest plugin that allows recording network interactions via VCR.py
MIT License
425 stars 34 forks source link

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

Closed AndreCimander closed 3 years ago

AndreCimander commented 3 years ago

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):

Stranger6667 commented 3 years ago

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 commented 3 years ago

@AndreCimander

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

AndreCimander commented 3 years ago

Works like a charm, thank you for the quick reaction and fix! :+1:

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

Stranger6667 commented 3 years ago

Great to hear that! :)

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