1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88
|
# -*- coding: utf-8 -*-
import pytest
from pytest_recording.plugin import RECORD_MODES
@pytest.mark.parametrize(
"args, expected",
[(("--record-mode={}".format(mode),), mode) for mode in RECORD_MODES] + [((), "none")],
)
def test_record_mode(testdir, args, expected):
testdir.makepyfile(
"""
def test_mode(record_mode):
assert record_mode == "{}"
""".format(expected)
)
# Record mode depends on the passed CMD arguments
result = testdir.runpytest(*args)
result.assert_outcomes(passed=1)
assert result.ret == 0
def test_help_message(testdir):
result = testdir.runpytest("--help")
result.stdout.fnmatch_lines(["recording:", "*--record-mode=*", "*VCR.py record mode.*"])
def test_pytest_vcr_incompatibility(testdir, mocker):
try:
mocker.patch("pluggy._manager.PluginManager.has_plugin", return_value=True)
except (AttributeError, ImportError):
# Older `pluggy`
mocker.patch("pluggy.manager.PluginManager.has_plugin", return_value=True)
testdir.makepyfile(
"""
def test_():
pass
"""
)
# Record mode depends on the passed CMD arguments
result = testdir.runpytest()
assert (
"INTERNALERROR> RuntimeError: `pytest-recording` is incompatible with `pytest-vcr`. "
"Please, uninstall `pytest-vcr` in order to use `pytest-recording`." in result.errlines
)
assert result.ret == 3
def test_default_cassette_marker(testdir):
# When the `default_cassette` marker is defined
testdir.makepyfile(
"""
import pytest
CASSETTE_NAME = "foo.yaml"
@pytest.mark.default_cassette(CASSETTE_NAME)
def test_marker(default_cassette_name):
assert default_cassette_name == CASSETTE_NAME
"""
)
# Then the default_cassette_name fixture should be overridden
result = testdir.runpytest()
result.assert_outcomes(passed=1)
assert result.ret == 0
def test_lazy_vcr_config(testdir):
# When test does not involve VCR
testdir.makepyfile(
"""
import pytest
@pytest.fixture
def vcr_config():
raise RuntimeError("Should not run")
def test_marker():
pass
"""
)
# Then the `vcr_config` fixture should not be evaluated
result = testdir.runpytest()
result.assert_outcomes(passed=1)
assert result.ret == 0
|