|
1 | 1 | # mypy: allow-untyped-defs
|
2 | 2 | from __future__ import annotations
|
3 | 3 |
|
| 4 | +from collections.abc import Sequence |
4 | 5 | import dataclasses
|
5 | 6 | import importlib.metadata
|
6 | 7 | import os
|
@@ -970,28 +971,39 @@ def test_calls_showall(self, pytester: Pytester, mock_timing) -> None:
|
970 | 971 | pytester.makepyfile(self.source)
|
971 | 972 | result = pytester.runpytest_inprocess("--durations=0")
|
972 | 973 | assert result.ret == 0
|
973 |
| - |
974 |
| - tested = "3" |
975 |
| - for x in tested: |
976 |
| - for y in ("call",): # 'setup', 'call', 'teardown': |
977 |
| - for line in result.stdout.lines: |
978 |
| - if (f"test_{x}") in line and y in line: |
979 |
| - break |
980 |
| - else: |
981 |
| - raise AssertionError(f"not found {x} {y}") |
| 974 | + print(result.stdout) |
| 975 | + TestDurations.check_tests_in_output(result.stdout.lines, "23") |
982 | 976 |
|
983 | 977 | def test_calls_showall_verbose(self, pytester: Pytester, mock_timing) -> None:
|
984 | 978 | pytester.makepyfile(self.source)
|
985 | 979 | result = pytester.runpytest_inprocess("--durations=0", "-vv")
|
986 | 980 | assert result.ret == 0
|
| 981 | + TestDurations.check_tests_in_output(result.stdout.lines, "123") |
987 | 982 |
|
988 |
| - for x in "123": |
989 |
| - for y in ("call",): # 'setup', 'call', 'teardown': |
990 |
| - for line in result.stdout.lines: |
991 |
| - if (f"test_{x}") in line and y in line: |
992 |
| - break |
993 |
| - else: |
994 |
| - raise AssertionError(f"not found {x} {y}") |
| 983 | + def test_calls_showall_durationsmin(self, pytester: Pytester, mock_timing) -> None: |
| 984 | + pytester.makepyfile(self.source) |
| 985 | + result = pytester.runpytest_inprocess("--durations=0", "--durations-min=0.015") |
| 986 | + assert result.ret == 0 |
| 987 | + TestDurations.check_tests_in_output(result.stdout.lines, "3") |
| 988 | + |
| 989 | + def test_calls_showall_durationsmin_verbose( |
| 990 | + self, pytester: Pytester, mock_timing |
| 991 | + ) -> None: |
| 992 | + pytester.makepyfile(self.source) |
| 993 | + result = pytester.runpytest_inprocess( |
| 994 | + "--durations=0", "--durations-min=0.015", "-vv" |
| 995 | + ) |
| 996 | + assert result.ret == 0 |
| 997 | + TestDurations.check_tests_in_output(result.stdout.lines, "3") |
| 998 | + |
| 999 | + @staticmethod |
| 1000 | + def check_tests_in_output(lines: Sequence[str], expected_test_numbers: str) -> None: |
| 1001 | + found_test_numbers = "".join( |
| 1002 | + test_number |
| 1003 | + for test_number in "123" |
| 1004 | + if any(f"test_{test_number}" in line and " call " in line for line in lines) |
| 1005 | + ) |
| 1006 | + assert found_test_numbers == expected_test_numbers |
995 | 1007 |
|
996 | 1008 | def test_with_deselected(self, pytester: Pytester, mock_timing) -> None:
|
997 | 1009 | pytester.makepyfile(self.source)
|
|
0 commit comments