Skip to content
Open
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Next Next commit
Move script_runner fixture to session scope
Requires its dependencies to also me moved to the session scope,
`tmp_path` was function-scoped and must be replaced with `tmp_path_factory`.

Needed to work well with custom fixtures, Fixes #89

ScriptRunner attributes marked as Final to document and enforce them as read-only
  • Loading branch information
HexDecimal committed Nov 13, 2025
commit a8bf302286722a9f38d8510f4684167850b20a3c
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,10 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0

## [Unreleased]

### Changed
- `script_runner` is now a session-scoped fixture.
[#89](https://github.com/kvas-it/pytest-console-scripts/issues/89)

## [1.4.1] - 2023-05-29

### Removed
Expand Down
20 changes: 9 additions & 11 deletions pytest_console_scripts/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
import traceback
import warnings
from pathlib import Path
from typing import Any, Callable, Iterator, Sequence, Union
from typing import Any, Callable, Final, Iterator, Sequence, Union
from unittest import mock

import pytest
Expand Down Expand Up @@ -234,9 +234,9 @@ def __init__(
print_result: bool = True
) -> None:
assert launch_mode in {'inprocess', 'subprocess'}
self.launch_mode = launch_mode
self.print_result = print_result
self.rootdir = rootdir
self.launch_mode: Final = launch_mode
self.print_result: Final = print_result
self.rootdir: Final = rootdir

def __repr__(self) -> str:
return f'<ScriptRunner {self.launch_mode}>'
Expand Down Expand Up @@ -455,19 +455,17 @@ def run_subprocess(
return RunResult(cp.returncode, cp.stdout, cp.stderr, print_result)


@pytest.fixture
@pytest.fixture(scope="session")
def script_launch_mode(request: pytest.FixtureRequest) -> str:
return str(request.param)


@pytest.fixture
def script_cwd(tmp_path: Path) -> Path:
work_dir = tmp_path / 'script-cwd'
work_dir.mkdir()
return work_dir
@pytest.fixture(scope="session")
def script_cwd(tmp_path_factory: pytest.TempPathFactory) -> Path:
return tmp_path_factory.mktemp('script-cwd')


@pytest.fixture
@pytest.fixture(scope="session")
def script_runner(
request: pytest.FixtureRequest, script_cwd: Path, script_launch_mode: str
) -> ScriptRunner:
Expand Down