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

Code before:
        pytester.makepyfile(self.source)
        result = pytester.runpytest_inprocess("--durations=2")
        assert result.ret == 0

        lines = result.stdout.get_lines_after("*slowest*durations*")
        assert "4 passed" in lines[2]

    def test_calls_showall(self, pytester: Pytester, mock_timing) -> None:
        pytester.makepyfile(self.source)
        result = pytester.runpytest_inprocess("--durations=0")
        assert result.ret == 0
        print(result.stdout)
        TestDurations.check_tests_in_output(result.stdout.lines, "23")

    def test_calls_showall_verbose(self, pytester: Pytester, mock_timing) -> None:
        pytester.makepyfile(self.source)
        result = pytester.runpytest_inprocess("--durations=0", "-vv")
        assert result.ret == 0
        TestDurations.check_tests_in_output(result.stdout.lines, "123")

    def test_calls_showall_durationsmin(self, pytester: Pytester, mock_timing) -> None:
        pytester.makepyfile(self.source)
        result = pytester.runpytest_inprocess("--durations=0", "--durations-min=0.015")
        assert result.ret == 0
        TestDurations.check_tests_in_output(result.stdout.lines, "3")

    def test_calls_showall_durationsmin_verbose(
        self, pytester: Pytester, mock_timing
    ) -> None:
        pytester.makepyfile(self.source)
        result = pytester.runpytest_inprocess(
            "--durations=0", "--durations-min=0.015", "-vv"
        )
        assert result.ret == 0
        TestDurations.check_tests_in_output(result.stdout.lines, "3")

    @staticmethod
    def check_tests_in_output(lines: Sequence[str], expected_test_numbers: str) -> None:
        found_test_numbers = "".join(
            test_number
            for test_number in "123"
            if any(f"test_{test_number}" in line and " call " in line for line in lines)
        )
        assert found_test_numbers == expected_test_numbers

    def test_with_deselected(self, pytester: Pytester, mock_timing) -> None:
        pytester.makepyfile(self.source)
        result = pytester.runpytest_inprocess("--durations=2", "-k test_3")
        assert result.ret == 0

        result.stdout.fnmatch_lines(["*durations*", "*call*test_3*"])

Review comment (bug):
This is the actual test that fails without the change in `src/_pytest/runner.py`.

Code after:
        pytester.makepyfile(self.source)
        result = pytester.runpytest_inprocess("--durations=2")
        assert result.ret == 0

        lines = result.stdout.get_lines_after("*slowest*durations*")
        assert "4 passed" in lines[2]

    def test_calls_showall(self, pytester: Pytester, mock_timing) -> None:
        pytester.makepyfile(self.source)
        result = pytester.runpytest_inprocess("--durations=0")
        assert result.ret == 0
        TestDurations.check_tests_in_output(result.stdout.lines, 2, 3)

    def test_calls_showall_verbose(self, pytester: Pytester, mock_timing) -> None:
        pytester.makepyfile(self.source)
        result = pytester.runpytest_inprocess("--durations=0", "-vv")
        assert result.ret == 0
        TestDurations.check_tests_in_output(result.stdout.lines, 1, 2, 3)

    def test_calls_showall_durationsmin(self, pytester: Pytester, mock_timing) -> None:
        pytester.makepyfile(self.source)
        result = pytester.runpytest_inprocess("--durations=0", "--durations-min=0.015")
        assert result.ret == 0
        TestDurations.check_tests_in_output(result.stdout.lines, 3)

    def test_calls_showall_durationsmin_verbose(
        self, pytester: Pytester, mock_timing
    ) -> None:
        pytester.makepyfile(self.source)
        result = pytester.runpytest_inprocess(
            "--durations=0", "--durations-min=0.015", "-vv"
        )
        assert result.ret == 0
        TestDurations.check_tests_in_output(result.stdout.lines, 3)

    @staticmethod
    def check_tests_in_output(
        lines: Sequence[str], *expected_test_numbers: int, number_of_tests: int = 3
    ) -> None:
        found_test_numbers = set(
            test_number
            for test_number in range(1, number_of_tests + 1)
            if any(
                line.endswith(f"test_{test_number}") and " call " in line
                for line in lines
            )
        )
        assert found_test_numbers == set(expected_test_numbers)

    def test_with_deselected(self, pytester: Pytester, mock_timing) -> None:
        pytester.makepyfile(self.source)