|
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,43 @@ 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 | + TestDurations.check_tests_in_output(result.stdout.lines, 2, 3) |
982 | 975 |
|
983 | 976 | def test_calls_showall_verbose(self, pytester: Pytester, mock_timing) -> None:
|
984 | 977 | pytester.makepyfile(self.source)
|
985 | 978 | result = pytester.runpytest_inprocess("--durations=0", "-vv")
|
986 | 979 | assert result.ret == 0
|
| 980 | + TestDurations.check_tests_in_output(result.stdout.lines, 1, 2, 3) |
| 981 | + |
| 982 | + def test_calls_showall_durationsmin(self, pytester: Pytester, mock_timing) -> None: |
| 983 | + pytester.makepyfile(self.source) |
| 984 | + result = pytester.runpytest_inprocess("--durations=0", "--durations-min=0.015") |
| 985 | + assert result.ret == 0 |
| 986 | + TestDurations.check_tests_in_output(result.stdout.lines, 3) |
| 987 | + |
| 988 | + def test_calls_showall_durationsmin_verbose( |
| 989 | + self, pytester: Pytester, mock_timing |
| 990 | + ) -> None: |
| 991 | + pytester.makepyfile(self.source) |
| 992 | + result = pytester.runpytest_inprocess( |
| 993 | + "--durations=0", "--durations-min=0.015", "-vv" |
| 994 | + ) |
| 995 | + assert result.ret == 0 |
| 996 | + TestDurations.check_tests_in_output(result.stdout.lines, 3) |
987 | 997 |
|
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}") |
| 998 | + @staticmethod |
| 999 | + def check_tests_in_output( |
| 1000 | + lines: Sequence[str], *expected_test_numbers: int, number_of_tests: int = 3 |
| 1001 | + ) -> None: |
| 1002 | + found_test_numbers = set( |
| 1003 | + test_number |
| 1004 | + for test_number in range(1, number_of_tests + 1) |
| 1005 | + if any( |
| 1006 | + line.endswith(f"test_{test_number}") and " call " in line |
| 1007 | + for line in lines |
| 1008 | + ) |
| 1009 | + ) |
| 1010 | + assert found_test_numbers == set(expected_test_numbers) |
995 | 1011 |
|
996 | 1012 | def test_with_deselected(self, pytester: Pytester, mock_timing) -> None:
|
997 | 1013 | pytester.makepyfile(self.source)
|
|
0 commit comments