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
|
import pytest
from helpers import pytester_path
@pytest.mark.parametrize(
"ini, cli, kwarg, expected",
[
("sty1", None, None, "sty1"),
("sty1", "sty2", None, "sty2"),
("sty1", "sty2", "sty3", "sty3"),
],
)
def test_config(pytester, ini, cli, kwarg, expected):
ini = "mpl-default-style = " + ini if ini else ""
pytester.makeini(
f"""
[pytest]
mpl-baseline-path = {pytester_path(pytester)}
{ini}
"""
)
kwarg = f"style='{kwarg}'" if kwarg else ""
pytester.makepyfile(
f"""
import matplotlib.pyplot as plt
import pytest
@pytest.mark.mpl_image_compare({kwarg})
def test_mpl():
fig, ax = plt.subplots()
ax.plot([1, 2, 3])
return fig
"""
)
cli = "--mpl-default-style=" + cli if cli else ""
result = pytester.runpytest("--mpl", cli)
result.assert_outcomes(failed=1)
result.stdout.fnmatch_lines([f"*OSError: *'{expected}'*"])
|