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

Code before:
    )
    group.addoption(
        "--sw-skip",
        "--stepwise-skip",
        action="store_true",
        default=False,
        dest="stepwise_skip",
        help="Ignore the first failing test but stop on the next failing test. "
        "Implicitly enables --stepwise.",
    )
    group.addoption(
        "--sw-reset",
        "--stepwise-reset",
        action="store_true",
        default=False,
        dest="stepwise_reset",
        help="Resets stepwise state, restarting the stepwise workflow. "
        "Implicitly enables --stepwise.",
    )


def pytest_configure(config: Config) -> None:
    # --stepwise-skip implies stepwise.
    if config.option.stepwise_skip:
        config.option.stepwise = True
    # --stepwise-clear implies stepwise.
    if config.option.stepwise_reset:
        config.option.stepwise = True
    if config.getoption("stepwise"):
        config.pluginmanager.register(StepwisePlugin(config), "stepwiseplugin")


def pytest_sessionfinish(session: Session) -> None:
    if not session.config.getoption("stepwise"):
        assert session.config.cache is not None
        if hasattr(session.config, "workerinput"):
            # Do not update cache if this process is a xdist worker to prevent
            # race conditions (#10641).
            return


@dataclasses.dataclass
class StepwiseCacheInfo:
    # The nodeid of the last failed test.
    last_failed: str | None

    # The number of tests in the last time --stepwise was run.
    # We use this information as a simple way to invalidate the cache information, avoiding
    # confusing behavior in case the cache is stale.
    last_test_count: int | None


Review comment (suggestion):
```suggestion
    # --stepwise-reset implies stepwise.
```

Code after:
    group.addoption(
        "--sw-skip",
        "--stepwise-skip",
        action="store_true",
        default=False,
        dest="stepwise_skip",
        help="Ignore the first failing test but stop on the next failing test. "
        "Implicitly enables --stepwise.",
    )
    group.addoption(
        "--sw-reset",
        "--stepwise-reset",
        action="store_true",
        default=False,
        dest="stepwise_reset",
        help="Resets stepwise state, restarting the stepwise workflow. "
        "Implicitly enables --stepwise.",
    )


def pytest_configure(config: Config) -> None:
    # --stepwise-skip/--stepwise-reset implies stepwise.
    if config.option.stepwise_skip or config.option.stepwise_reset:
        config.option.stepwise = True
    if config.getoption("stepwise"):
        config.pluginmanager.register(StepwisePlugin(config), "stepwiseplugin")


def pytest_sessionfinish(session: Session) -> None:
    if not session.config.getoption("stepwise"):
        assert session.config.cache is not None
        if hasattr(session.config, "workerinput"):
            # Do not update cache if this process is a xdist worker to prevent
            # race conditions (#10641).
            return


@dataclasses.dataclass
class StepwiseCacheInfo:
    # The nodeid of the last failed test.
    last_failed: str | None

    # The number of tests in the last time --stepwise was run.
    # We use this information as a simple way to invalidate the cache information, avoiding
    # confusing behavior in case the cache is stale.
    last_test_count: int | None

    # The date when the cache was last updated, for information purposes only.
    last_cache_date_str: str

    @property