File: test_maxfail.py

package info (click to toggle)
pytest-check 2.7.6-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 480 kB
  • sloc: python: 2,220; sh: 17; makefile: 6
file content (47 lines) | stat: -rw-r--r-- 1,255 bytes parent folder | download
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
from typing import Callable, Dict, List, Optional

import pytest


@pytest.mark.parametrize(
    "maxfail,expected_outcomes,expected_lines",
    [
        (
            1,
            {"failed": 1, "passed": 0},
            ["*AssertionError: one*"],
        ),
        (
            2,
            {"failed": 2, "passed": 0},
            [
                "*FAILURE: one",
                "*FAILURE: two",
                "*FAILURE: three",
                "*Failed Checks: 3*",
            ],
        ),
        (
            3,
            {"failed": 2, "passed": 1},
            None,
        ),
    ],
)
def test_maxfail_behavior(
    run_example_test: Callable,
    maxfail: int,
    expected_outcomes: Dict[str, int],
    expected_lines: Optional[List[str]],
) -> None:
    """
    Test that --maxfail correctly stops after N failed tests (not checks).

    - maxfail=1: Should stop after first failed check
    - maxfail=2: Should stop after 2 tests (not checks)
    - maxfail=3: Should not stop on checks, runs at least 3 tests
    """
    result = run_example_test("test_example_maxfail.py", None, f"--maxfail={maxfail}")
    result.assert_outcomes(**expected_outcomes)
    if expected_lines:
        result.stdout.fnmatch_lines(expected_lines)