A pytest plugin: the slow marker and --fast mode
Implement a pytest plugin module. `reference.py` is loaded into pytest via
`-p reference` and must define hooks with the exact names below.
**1. `pytest_addoption(parser)`** — add the `--fast` flag:
- `action="store_true"`, `default=False`;
- a non-empty help string.
**2. `pytest_configure(config)`** — register the marker:
```python
config.addinivalue_line("markers", "slow: ...")
```
The line must start with `slow:` and contain a description.
**3. `pytest_collection_modifyitems(config, items)`**:
- a slow test is an item whose `item.get_closest_marker("slow")` is not `None`;
- without `--fast` no item is modified and no item gets a skip marker;
- with `--fast`, add `pytest.mark.skip(reason="--fast: slow test skipped")` to
every slow item via `item.add_marker(...)`;
- store the counters on `config.slow_stats`:
```python
{"total": <all slow tests>, "skipped": <how many were skipped>}
```
- the order of `items` does not change;
- non-slow tests get no markers and no exceptions.
**4. `pytest_terminal_summary(terminalreporter, config)`**:
- if there is no `slow_stats` or `total == 0`, write nothing;
- otherwise write exactly one line via `terminalreporter.write_line`:
```
slow tests: {total} found, {skipped} skipped
```
The hooks are called directly with stub objects that implement only the methods
they use: `parser.addoption`, `config.getoption("--fast")`,
`config.addinivalue_line`, `item.get_closest_marker`, `item.add_marker`,
`terminalreporter.write_line`. A hook may accept any subset of the standard
pytest arguments (`parser`, `pluginmanager`, `session`, `config`, `items`,
`terminalreporter`, `exitstatus`); the tests pass them by name. No files,
network, or global state: the counters live on `config`.
**Example:**
```python
items = [slow_item, fast_item]
config = FakeConfig(fast=True)
pytest_collection_modifyitems(config, items)
config.slow_stats # {"total": 1, "skipped": 1}
slow_item.added_markers[0].name # "skip"
```
The AI mentor is available after you log in: it sees your attempt history and does not spend resources on anonymous requests.
Log in and askHint 1
At which pytest lifecycle stage should the flag be added, and at which one should the marker be registered? And where should the counters live so that two runs in one process do not mix them up?