Repository: pytest-dev/pytest
File: src/_pytest/stepwise.py (Python)

Code before:

        if not self.cached_info.last_failed:
            self.report_status.append("no previously failed tests, not skipping.")
            return

        if last_test_count is not None and last_test_count != len(items):
            self.report_status.append(
                f"test count changed, not skipping (now {len(items)} tests, previously {last_test_count})."
            )
            self.cached_info.last_failed = None
            return

        # Check all item nodes until we find a match on last failed.
        failed_index = None
        for index, item in enumerate(items):
            if item.nodeid == self.cached_info.last_failed:
                failed_index = index
                break

        # If the previously failed test was not found among the test items,
        # do not skip any tests.
        if failed_index is None:
            self.report_status.append("previously failed test not found, not skipping.")
        else:
            self.report_status.append(
                f"skipping {failed_index} already passed items (cache from {self.cached_info.last_cache_date},"
                f" use --sw-reset to discard)."
            )
            deselected = items[:failed_index]
            del items[:failed_index]
            config.hook.pytest_deselected(items=deselected)

    def pytest_runtest_logreport(self, report: TestReport) -> None:
        if report.failed:
            if self.skip:
                # Remove test from the failed ones (if it exists) and unset the skip option
                # to make sure the following tests will not be skipped.
                if report.nodeid == self.cached_info.last_failed:
                    self.cached_info.last_failed = None

                self.skip = False
            else:
                # Mark test as the last failing and interrupt the test session.
                self.cached_info.last_failed = report.nodeid
                assert self.session is not None
                self.session.shouldstop = (
                    "Test failed, continuing from this test next run."
                )

        else:
            # If the test was actually run and did pass.

Review comment (bug):
```suggestion
                f"skipping {failed_index} already passed items (cache from {self.cached_info.last_cache_date:%c},"
```

maybe, where `%c` is ["Locale’s appropriate date and time representation."](https://docs.python.org/3/library/datetime.html#strftime-and-strptime-format-codes)?

Without this, it gets displayed as e.g. `cache from 2025-01-15 14:25:45.458813` which seems a bit verbose, and the fractional seconds don't really add any useful information.

Code after:
            return

        if not self.cached_info.last_failed:
            self.report_status.append("no previously failed tests, not skipping.")
            return

        if last_test_count is not None and last_test_count != len(items):
            self.report_status.append(
                f"test count changed, not skipping (now {len(items)} tests, previously {last_test_count})."
            )
            self.cached_info.last_failed = None
            return

        # Check all item nodes until we find a match on last failed.
        failed_index = None
        for index, item in enumerate(items):
            if item.nodeid == self.cached_info.last_failed:
                failed_index = index
                break

        # If the previously failed test was not found among the test items,
        # do not skip any tests.
        if failed_index is None:
            self.report_status.append("previously failed test not found, not skipping.")
        else:
            cache_age = datetime.now() - self.cached_info.last_cache_date
            # Round up to avoid showing microseconds.
            cache_age = timedelta(seconds=int(cache_age.total_seconds()))
            self.report_status.append(
                f"skipping {failed_index} already passed items (cache from {cache_age} ago,"
                f" use --sw-reset to discard)."
            )
            deselected = items[:failed_index]
            del items[:failed_index]
            config.hook.pytest_deselected(items=deselected)

    def pytest_runtest_logreport(self, report: TestReport) -> None:
        if report.failed:
            if self.skip:
                # Remove test from the failed ones (if it exists) and unset the skip option
                # to make sure the following tests will not be skipped.
                if report.nodeid == self.cached_info.last_failed:
                    self.cached_info.last_failed = None

                self.skip = False
            else:
                # Mark test as the last failing and interrupt the test session.
                self.cached_info.last_failed = report.nodeid
                assert self.session is not None
                self.session.shouldstop = (
                    "Test failed, continuing from this test next run."