File: test_speedup_functions.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 (89 lines) | stat: -rw-r--r-- 2,647 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
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
89
import pytest


def test_baseline(pytester):
    pytester.copy_example("examples/test_example_speedup_funcs.py")
    result = pytester.runpytest("-k baseline", "--check-max-tb=10")
    result.assert_outcomes(failed=1)
    result.stdout.fnmatch_lines(
        [
            "*FAILURE: * 7 == 100",
            "*test_baseline() -> check.equal(i, 100)",
            "*FAILURE: * 8 == 100",
            "*test_baseline() -> check.equal(i, 100)",
            "*FAILURE: * 9 == 100",
            "*test_baseline() -> check.equal(i, 100)",
            "Failed Checks: 10",
        ],
    )


def test_max_report(pytester):
    pytester.copy_example("examples/test_example_speedup_funcs.py")
    result = pytester.runpytest("-k max_report")
    result.assert_outcomes(failed=1)
    result.stdout.fnmatch_lines(
        [
            "*FAILURE: * 1 == 100",
            "*FAILURE: * 2 == 100",
            "*FAILURE: * 3 == 100",
            "*FAILURE: * 4 == 100",
            "*FAILURE: * 5 == 100",
            "Failed Checks: 10",
        ],
    )
    result.stdout.no_fnmatch_line("*FAILURE: * 6 == 100")


def test_max_fail(pytester):
    pytester.copy_example("examples/test_example_speedup_funcs.py")
    result = pytester.runpytest("-k max_fail")
    result.assert_outcomes(failed=1)
    result.stdout.fnmatch_lines(
        [
            "*FAILURE: * 1 == 100",
            "*FAILURE: * 2 == 100",
            "*FAILURE: * 3 == 100",
            "*FAILURE: * 4 == 100",
            "*FAILURE: * 5 == 100",
            "Failed Checks: 5",
            "*AssertionError: pytest-check max fail of 5 reached",
        ],
    )
    result.stdout.no_fnmatch_line("*FAILURE: * 6 == 100")


def test_max_tb(pytester):
    pytester.copy_example("examples/test_example_speedup_funcs.py")
    result = pytester.runpytest("-k max_tb", "--show-capture=no")
    result.assert_outcomes(failed=1)
    num_tb = str(result.stdout).count("in test_max_tb() -> check.equal(i, 100)")
    assert num_tb == 2


def test_deprecated_no_tb(check):
    with pytest.deprecated_call():
        check.set_no_tb()


text_for_test_no_tb = """
def test_no_tb(check):
    check.set_no_tb()
    for i in range(1, 11):
        check.equal(i, 100)
"""


def test_no_tb(pytester):
    pytester.makepyfile(text_for_test_no_tb)
    result = pytester.runpytest("-k no_tb")
    result.assert_outcomes(failed=1)
    result.stdout.fnmatch_lines(
        [
            "*FAILURE: * 7 == 100",
            "*FAILURE: * 8 == 100",
            "*FAILURE: * 9 == 100",
            "Failed Checks: 10",
        ],
    )
    result.stdout.no_fnmatch_line("*test_baseline() -> check.equal(i, 100)")