File: test_parse_stdout.py

package info (click to toggle)
dask.distributed 2022.12.1%2Bds.1-3
  • links: PTS, VCS
  • area: main
  • in suites: bookworm
  • size: 10,164 kB
  • sloc: python: 81,938; javascript: 1,549; makefile: 228; sh: 100
file content (100 lines) | stat: -rw-r--r-- 5,368 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
90
91
92
93
94
95
96
97
98
99
100
from __future__ import annotations

import os
import re
import sys

import pytest

script_dir = os.path.join(
    os.path.dirname(__file__), "..", "..", "continuous_integration", "scripts"
)
sys.path.append(script_dir)
# Will fail if test suite was pip-installed
parse_stdout = pytest.importorskip("parse_stdout")


# Note: test_timeout below ends with a whitespace!
# flake8: noqa: W291
stdout = """
Unrelated row, must ignore
distributed/tests/test1.py::test_fail FAILED                             [ 10%]
distributed/tests/test1.py::test_error_in_setup ERROR                    [ 20%]
distributed/tests/test1.py::test_pass_and_then_error_in_teardown PASSED  [ 30%]
distributed/tests/test1.py::test_pass_and_then_error_in_teardown ERROR   [ 30%]
distributed/tests/test1.py::test_fail_and_then_error_in_teardown FAILED  [ 40%]
distributed/tests/test1.py::test_fail_and_then_error_in_teardown ERROR   [ 40%]
distributed/tests/test1.py::test_skip SKIPPED (unconditional skip)       [ 50%]
distributed/tests/test1.py::test_xfail XFAIL                             [ 60%]
distributed/tests/test1.py::test_flaky RERUN                             [ 70%]
distributed/tests/test1.py::test_flaky PASSED                            [ 70%]
distributed/tests/test1.py::test_leaking PASSED                          [ 72%]
distributed/tests/test1.py::test_leaking LEAKED                          [ 72%]
distributed/tests/test1.py::test_pass PASSED                             [ 75%]
distributed/tests/test1.py::test_params[a a] PASSED                      [ 78%]
distributed/tests/test1.py::test_escape_chars[<lambda>] PASSED           [ 80%]
distributed/tests/test1.py::MyTest::test_unittest PASSED                 [ 86%]
distributed/tests/test1.py::test_timeout 
"""


def test_parse_rows():
    actual = parse_stdout.parse_rows(stdout.splitlines())

    expect = [
        ("distributed.tests.test1", "test_fail", {"FAILED"}),
        ("distributed.tests.test1", "test_error_in_setup", {"ERROR"}),
        (
            "distributed.tests.test1",
            "test_pass_and_then_error_in_teardown",
            {"PASSED", "ERROR"},
        ),
        (
            "distributed.tests.test1",
            "test_fail_and_then_error_in_teardown",
            {"FAILED", "ERROR"},
        ),
        ("distributed.tests.test1", "test_skip", {"SKIPPED"}),
        ("distributed.tests.test1", "test_xfail", {"XFAIL"}),
        ("distributed.tests.test1", "test_flaky", {"PASSED"}),
        ("distributed.tests.test1", "test_leaking", {"PASSED"}),
        ("distributed.tests.test1", "test_pass", {"PASSED"}),
        ("distributed.tests.test1", "test_params[a a]", {"PASSED"}),
        ("distributed.tests.test1", "test_escape_chars[<lambda>]", {"PASSED"}),
        ("distributed.tests.test1.MyTest", "test_unittest", {"PASSED"}),
        ("distributed.tests.test1", "test_timeout", {None}),
    ]

    assert actual == expect


def test_build_xml(capsys):
    rows = parse_stdout.parse_rows(stdout.splitlines())
    parse_stdout.build_xml(rows)
    actual = capsys.readouterr().out.strip()
    # Remove timestamp
    actual = re.sub(r"\d{4}-\d{2}-\d{2}T\d{2}:\d{2}:\d{2}.\d{6}", r"snip", actual)

    expect = """
<?xml version="1.0" encoding="utf-8"?>
<testsuites>
<testsuite name="distributed" errors="3" failures="3" skipped="2" tests="15" time="0.0" timestamp="snip" hostname="">
<testcase classname="distributed.tests.test1" name="test_fail" time="0.0"><failure message=""></failure></testcase>
<testcase classname="distributed.tests.test1" name="test_error_in_setup" time="0.0"><error message="failed on setup"></error></testcase>
<testcase classname="distributed.tests.test1" name="test_pass_and_then_error_in_teardown" time="0.0"><error message="failed on teardown"></error></testcase>
<testcase classname="distributed.tests.test1" name="test_fail_and_then_error_in_teardown" time="0.0"><failure message=""></failure></testcase>
<testcase classname="distributed.tests.test1" name="test_fail_and_then_error_in_teardown" time="0.0"><error message="failed on teardown"></error></testcase>
<testcase classname="distributed.tests.test1" name="test_skip" time="0.0"><skipped type="pytest.skip" message="skip"></skipped></testcase>
<testcase classname="distributed.tests.test1" name="test_xfail" time="0.0"><skipped type="pytest.xfail" message="xfail"></skipped></testcase>
<testcase classname="distributed.tests.test1" name="test_flaky" time="0.0" />
<testcase classname="distributed.tests.test1" name="test_leaking" time="0.0" />
<testcase classname="distributed.tests.test1" name="test_pass" time="0.0" />
<testcase classname="distributed.tests.test1" name="test_params[a a]" time="0.0" />
<testcase classname="distributed.tests.test1" name="test_escape_chars[&lt;lambda&gt;]" time="0.0" />
<testcase classname="distributed.tests.test1.MyTest" name="test_unittest" time="0.0" />
<testcase classname="distributed.tests.test1" name="test_timeout" time="0.0"><failure message="pytest-timeout exceeded"></failure></testcase>
</testsuite>
</testsuites>
    """.strip()

    assert actual == expect