Repository: pytest-dev/pytest
File: testing/test_terminal.py (Python)

Code before:
)
def test_format_session_duration(seconds, expected):
    from _pytest.terminal import format_session_duration

    assert format_session_duration(seconds) == expected


@pytest.mark.parametrize(
    "seconds, expected",
    [
        (3600 * 100 - 60, "99h 59m"),
        (31 * 60 - 1, "30m 59s"),
        (10.1236, "10.124s"),
        (9.1236, "9.124s"),
        (0.1236, "123.6ms"),
        (0.01236, "12.36ms"),
        (0.001236, "1.236ms"),
        (0.0001236, "123.6us"),
        (0.00001236, "12.36us"),
        (0.000001236, "1.236us"),
    ],
)
def test_format_node_duration(seconds, expected):
    from _pytest.terminal import format_node_duration

    assert format_node_duration(seconds) == expected


def test_collecterror(pytester: Pytester) -> None:
    p1 = pytester.makepyfile("raise SyntaxError()")
    result = pytester.runpytest("-ra", str(p1))
    result.stdout.fnmatch_lines(
        [
            "collected 0 items / 1 error",
            "*= ERRORS =*",
            "*_ ERROR collecting test_collecterror.py _*",
            "E   SyntaxError: *",
            "*= short test summary info =*",
            "ERROR test_collecterror.py",
            "*! Interrupted: 1 error during collection !*",
            "*= 1 error in *",
        ]
    )


def test_no_summary_collecterror(pytester: Pytester) -> None:
    p1 = pytester.makepyfile("raise SyntaxError()")
    result = pytester.runpytest("-ra", "--no-summary", str(p1))
    result.stdout.no_fnmatch_line("*= ERRORS =*")



Review comment (suggestion):
Nice testing this in a unittest!

```suggestion
def test_format_node_duration(seconds: float, expected: str) -> None:
    from _pytest.terminal import format_node_duration

    assert format_node_duration(seconds) == expected
```

Code after:
    # No truncation with -vv.
    result = pytester.runpytest("-vv")
    result.stdout.fnmatch_lines(
        [
            "*short test summary info*",
            f"*{'A' * string_length}*{'B' * string_length}'",
        ]
    )


@pytest.mark.parametrize(
    "seconds, expected",
    [
        (10.0, "10.00s"),
        (10.34, "10.34s"),
        (59.99, "59.99s"),
        (60.55, "60.55s (0:01:00)"),
        (123.55, "123.55s (0:02:03)"),
        (60 * 60 + 0.5, "3600.50s (1:00:00)"),
    ],
)
def test_format_session_duration(seconds, expected):
    from _pytest.terminal import format_session_duration

    assert format_session_duration(seconds) == expected


@pytest.mark.parametrize(
    "seconds, expected",
    [
        (3600 * 100 - 60, " 99h 59m"),
        (31 * 60 - 1, " 30m 59s"),
        (10.1236, " 10.124s"),
        (9.1236, " 9.124s"),
        (0.1236, " 123.6ms"),
        (0.01236, " 12.36ms"),
        (0.001236, " 1.236ms"),
        (0.0001236, " 123.6us"),
        (0.00001236, " 12.36us"),
        (0.000001236, " 1.236us"),
    ],
)
def test_format_node_duration(seconds: float, expected: str) -> None:
    from _pytest.terminal import format_node_duration

    assert format_node_duration(seconds) == expected


def test_collecterror(pytester: Pytester) -> None:
    p1 = pytester.makepyfile("raise SyntaxError()")
    result = pytester.runpytest("-ra", str(p1))