File: test_results_path.py

package info (click to toggle)
pytest-mpl 0.17.0-2
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 2,132 kB
  • sloc: python: 2,514; javascript: 179; makefile: 16
file content (35 lines) | stat: -rw-r--r-- 903 bytes parent folder | download | duplicates (2)
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
import pytest
from helpers import pytester_path


@pytest.mark.parametrize(
    "ini, cli, expected",
    [
        ("dir1", None, "dir1"),
        ("dir1", "dir2", "dir2"),
        (None, "dir2", "dir2"),
    ],
)
def test_config(pytester, ini, cli, expected):
    ini = f"mpl-results-path = {ini}" if ini else ""
    pytester.makeini(
        f"""
        [pytest]
        {ini}
        """
    )
    pytester.makepyfile(
        """
        import matplotlib.pyplot as plt
        import pytest
        @pytest.mark.mpl_image_compare
        def test_mpl():
            fig, ax = plt.subplots()
            ax.plot([1, 2, 3])
            return fig
        """
    )
    cli = f"--mpl-results-path={cli}" if cli else ""
    result = pytester.runpytest("--mpl", cli)
    result.assert_outcomes(failed=1)
    assert (pytester_path(pytester) / expected / "test_config.test_mpl" / "result.png").exists()