API¶
Pytest fixture plugin for pyrig-managed projects.
Supplies a shared pool of pytest fixtures that pyrig's dependency-discovery mechanism registers automatically in every dependent project's test suite, along with the tooling to generate and extend that fixture set.
rig ¶
Mirrored namespace through which this plugin extends pyrig's scaffolding.
Mirrors the pyrig.rig package layout so pyrig's cross-package plugin
discovery finds this package's fixtures, configuration, and CLI
customizations automatically.
cli ¶
CLI commands that pyrig-fixtures adds to the mk scaffolding command group.
fixture ¶
Scaffold a new pytest fixture stub in the project's shared fixtures module.
Appends an @pytest.fixture-decorated function stub to the shared fixtures
module. The file is created if it does not already exist. If import pytest
is not already present in the module, it is inserted automatically.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
name
|
Annotated[str, Argument(help='Name of the fixture to create.')]
|
Name of the fixture to create. Accepts kebab-case or snake_case;
kebab-case is normalized to snake_case to form a valid identifier
(e.g. |
required |
Source code in src/pyrig_fixtures/rig/cli/__init__.py
commands ¶
Backend implementations for the pyrig-fixtures CLI commands.
Each module implements one command as a plain callable, decoupled from the CLI registration layer so it can be imported lazily when the command runs.
make ¶
Backend implementations for the pyrig-fixtures scaffolding subcommands.
fixture ¶
Scaffolding for shared pytest fixtures in a pyrig-managed project.
make_fixture(name: str) -> None
Scaffold a new pytest fixture in the project's shared fixtures module.
Ensures the shared fixtures module exists, then appends a new
@pytest.fixture-decorated function with the given name. If
import pytest is not already present in the module, it is added
before the new fixture.
The name is normalized from kebab-case to snake_case so it forms a
valid Python identifier (e.g. "my-new-fixture" becomes
"my_new_fixture").
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
name
|
str
|
Name of the fixture in kebab-case or snake_case. |
required |
Source code in src/pyrig_fixtures/rig/cli/commands/make/fixture.py
configs ¶
Declarative definitions of configuration files this package manages.
Mirrors pyrig's own config-file package path, so definitions placed here join pyrig's discovery scope and are validated alongside its built-in config files without any explicit registration.
conftest ¶
Configuration for the generated tests/conftest.py file.
Manages a conftest file that registers pyrig_fixtures' own conftest module as a pytest plugin, giving the target project access to it without an explicit import in each test file.
ConftestConfigFile ¶
Bases: CopyModuleDocstringConfigFile
The tests/conftest.py config file, generated for the target project.
The generated file has two parts: the module-level docstring of
pyrig_fixtures.rig.tests.conftest as its own module docstring, followed
by a pytest_plugins assignment that registers that module as a pytest
plugin, giving the target project automatic access to it without needing an
explicit import in each test file.
content ¶
content() -> str
Return the generated conftest.py file's content.
Returns:
| Type | Description |
|---|---|
str
|
The module docstring of |
str
|
by a |
str
|
pytest plugin. |
Source code in src/pyrig_fixtures/rig/configs/conftest.py
copy_module ¶
copy_module() -> ModuleType
is_correct ¶
is_correct() -> bool
Return whether the conftest module is already registered as a pytest plugin.
Returns:
| Type | Description |
|---|---|
bool
|
|
bool
|
listed in the |
Source code in src/pyrig_fixtures/rig/configs/conftest.py
plugin_definition ¶
plugin_definition() -> str
Return the pytest_plugins assignment line for the generated file.
Returns:
| Type | Description |
|---|---|
str
|
|
Source code in src/pyrig_fixtures/rig/configs/conftest.py
tests ¶
Pytest configuration root pooling fixtures across this package's dependents.
Fixtures defined in this package, and in the equivalent package of every installed package depending on it, are collected and made available to test suites without explicit imports.
conftest ¶
Pytest configuration for automatic fixture discovery across dependent packages.
Registers every fixture module in this package's fixtures package, and in the equivalent fixtures package of every installed package that depends on this package, as a pytest plugin. This makes all discovered fixtures available in every test module without explicit imports.
fixtures ¶
Shared pytest fixtures for pyrig and pyrig-based projects.
Each submodule groups fixtures for a single testing concern.
cli ¶
Shared pytest fixtures for testing the project's CLI commands.
Provides helpers that check whether a CLI command is registered and reachable, and whether a command delegates to its expected implementation function.
command_calls_function ¶
command_calls_function(
mocker: MockerFixture,
) -> Callable[
[FunctionType, FunctionType, Iterable[str]], bool
]
Return a callable that verifies a CLI command delegates to a function.
The returned callable registers cmd on a freshly built CLI app, patches
function where it is defined, invokes cmd through the CLI with
args, and reports whether the patch was called exactly once. Whether
the invocation itself succeeds is not checked.
Adds a second dummy command to prevent the only one command from being treated
as the default command.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
mocker
|
MockerFixture
|
pytest-mock fixture used to patch |
required |
Returns:
| Type | Description |
|---|---|
Callable[[FunctionType, FunctionType, Iterable[str]], bool]
|
A callable |
Callable[[FunctionType, FunctionType, Iterable[str]], bool]
|
|
Callable[[FunctionType, FunctionType, Iterable[str]], bool]
|
|
Source code in src/pyrig_fixtures/rig/tests/fixtures/cli.py
command_works ¶
command_works() -> Callable[[FunctionType], bool]
Return a callable that verifies a CLI command is registered and reachable.
The returned callable runs cmd as a subcommand of the project's CLI
with --help and checks whether its kebab-case name appears in stdout.
Returns:
| Type | Description |
|---|---|
Callable[[FunctionType], bool]
|
A callable |
Callable[[FunctionType], bool]
|
name appears in the |
Raises:
| Type | Description |
|---|---|
CalledProcessError
|
If invoking |
Source code in src/pyrig_fixtures/rig/tests/fixtures/cli.py
configs ¶
Shared pytest fixtures for testing ConfigFile subclasses in isolation.
Provides a factory that redirects a ConfigFile subclass's file operations
to pytest's tmp_path so tests never touch real project files.
config_file_factory ¶
config_file_factory[
T: ConfigFile[dict[str, Any] | list[Any]]
](tmp_path: Path) -> Callable[[type[T]], type[T]]
Return a factory that wraps a ConfigFile subclass for isolated testing.
Each call to the factory dynamically creates a new wrapping subclass, so
it may be invoked with a different ConfigFile subclass any number of
times within the same test.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
tmp_path
|
Path
|
Pytest's per-test temporary directory. |
required |
Returns:
| Type | Description |
|---|---|
Callable[[type[T]], type[T]]
|
A callable |
Callable[[type[T]], type[T]]
|
subclass whose file operations are redirected to |
Source code in src/pyrig_fixtures/rig/tests/fixtures/configs.py
environment ¶
Shared pytest fixtures for gating tests by platform and Python version.
Provides session-scoped predicates for the current OS and interpreter version, used to restrict environment-sensitive tests to a canonical CI environment while still running them locally.
on_latest_python_version ¶
Return whether the running Python version matches the latest stable release.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
on_python_version
|
Callable[[str], bool]
|
Callable that checks whether a given version string exactly matches the running Python version. |
required |
Returns:
| Type | Description |
|---|---|
bool
|
True if the current Python micro version matches the latest stable |
bool
|
release. |
Source code in src/pyrig_fixtures/rig/tests/fixtures/environment.py
on_linux ¶
Return whether the current system is Linux.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
on_platform
|
Callable[[str], bool]
|
Callable that checks whether a given platform name exactly matches the current system platform. |
required |
Returns:
| Type | Description |
|---|---|
bool
|
True if the system is Linux. |
Source code in src/pyrig_fixtures/rig/tests/fixtures/environment.py
on_linux_and_latest_python_version ¶
Return whether the current environment is Linux with the latest Python version.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
on_linux
|
bool
|
Whether the current system is Linux. |
required |
on_latest_python_version
|
bool
|
Whether the running Python version matches the latest stable release. |
required |
Returns:
| Type | Description |
|---|---|
bool
|
True if both conditions are met. |
Source code in src/pyrig_fixtures/rig/tests/fixtures/environment.py
on_linux_and_latest_python_version_or_not_in_ci ¶
on_linux_and_latest_python_version_or_not_in_ci(
*, on_linux_and_latest_python_version: bool
) -> bool
Return whether tests that require a canonical environment should run.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
on_linux_and_latest_python_version
|
bool
|
Whether the environment is Linux with the latest Python version. |
required |
Returns:
| Type | Description |
|---|---|
bool
|
True if the environment is Linux with the latest Python version, or |
bool
|
if not currently running inside GitHub Actions. |
Source code in src/pyrig_fixtures/rig/tests/fixtures/environment.py
on_platform ¶
Check whether the current system platform exactly matches a given name.
Returns:
| Type | Description |
|---|---|
Callable[[str], bool]
|
A callable |
Callable[[str], bool]
|
|
Callable[[str], bool]
|
|
Source code in src/pyrig_fixtures/rig/tests/fixtures/environment.py
on_python_version ¶
Check whether the current Python version exactly matches a given version string.
Returns:
| Type | Description |
|---|---|
Callable[[str], bool]
|
A callable |
Callable[[str], bool]
|
exactly equals |
Source code in src/pyrig_fixtures/rig/tests/fixtures/environment.py
fixtures ¶
Catch-all module for shared pytest fixtures with no more specific home.
Fixtures scaffolded without a dedicated topic are appended here rather than sorted into one of the other themed fixture modules.
claim_file ¶
Try to exclusively claim a <stem>.claimed marker file.
Every pytest-xdist worker's own base temp dir is <root>/<worker_id>,
so <root> is the same shared path in every worker regardless of how
many exist or how tests get distributed among them. Creating the marker
there via Path.touch(exist_ok=False) is atomic on every platform
pytest supports, so exactly one caller across all workers ever wins the
race.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
tmp_path_factory
|
TempPathFactory
|
Used to locate the shared |
required |
stem
|
str
|
Distinguishes this claim from any other's marker file. |
required |
Returns:
| Type | Description |
|---|---|
bool
|
|
bool
|
other caller. |
Source code in src/pyrig_fixtures/rig/tests/fixtures/fixtures.py
init_pyrig_project ¶
init_pyrig_project(
request: FixtureRequest,
tmp_path_factory: TempPathFactory,
) -> tuple[bool, str]
Verify that this project can be built and adopted by a fresh consumer project.
Delegates the actual build, install, and verification flow to
run_init_pyrig_project, once per test session, in an isolated
temporary directory. Skipped when --skip-init-pyrig-project is
passed.
Under pytest-xdist, every worker process would otherwise repeat this expensive flow independently. claim_file elects a single winner, across however many worker processes exist, to run it for real; outside of pytest-xdist there's only one process, so it always wins trivially.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
request
|
FixtureRequest
|
Used to read the |
required |
tmp_path_factory
|
TempPathFactory
|
Used to locate the shared dir to race for the claim in. |
required |
Returns:
| Type | Description |
|---|---|
bool
|
A tuple of |
str
|
since a failed check raises instead of returning. |
tuple[bool, str]
|
explains why the run was skipped, or is empty when it ran and |
tuple[bool, str]
|
succeeded. |
Raises:
| Type | Description |
|---|---|
Exception
|
If the check does not succeed. |
Note
Being autouse and session-scoped, a failed check reports a setup error for every test in the session, not just one. Under pytest-xdist, that only holds for the winning worker's own tests, since it's the only one that actually runs the check — the other workers' tests are unaffected either way, but the run as a whole still fails since the winner's tests do.
Source code in src/pyrig_fixtures/rig/tests/fixtures/fixtures.py
pytest_addoption ¶
Register the --skip-init-pyrig-project command-line flag.
The flag lets a run opt out of the expensive init_pyrig_project fixture that every project depending on pyrig-fixtures otherwise runs once per test session, e.g. for a fast local feedback loop.
A true single-dash short form (e.g. -sipp) isn't possible: pytest
reserves lowercase single-dash options for its own core and rejects
them from plugins, so --sipp is offered as the short alias instead.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
parser
|
Parser
|
Pytest's parser to register the command-line option on. |
required |
Source code in src/pyrig_fixtures/rig/tests/fixtures/fixtures.py
run_init_pyrig_project ¶
Build this project and verify a fresh consumer project can adopt it.
Packages the current project as a wheel and scaffolds a brand-new
project under tmp_path, adding the wheel plus every other
currently-installed plugin that depends on pyrig-runtime as dev
dependencies. Runs pyrig init in the new project, then checks that
its own test suite fails as expected, that its CLI and version
command produce the expected output, that the expected package
directory was generated, and that every ConfigFile subclass
produced its file. Finally runs pyrigger --help as a last sanity
check.
Kept as a standalone function, separate from init_pyrig_project, so tests can call it directly with mocked subprocess results to exercise each failure branch independently.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
tmp_path
|
Path
|
Scratch directory to scaffold the wheel-build copy of this project and the new consumer project under; must not already contain directories with their names. |
required |
monkeypatch
|
MonkeyPatch
|
Used to remove the current virtual environment from the environment for the duration of the run, so subprocess commands create and use their own fresh environment instead of reusing the caller's. |
required |
Returns:
| Type | Description |
|---|---|
bool
|
A tuple of |
str
|
every check above passes; |
tuple[bool, str]
|
that failed, or is empty when |
Raises:
| Type | Description |
|---|---|
CalledProcessError
|
If any underlying command fails, other than the new project's own test suite exiting as expected. |
Source code in src/pyrig_fixtures/rig/tests/fixtures/fixtures.py
140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 | |
modules ¶
Shared pytest fixtures for creating temporary modules and packages.
Provides callables that build real Python modules and packages on disk (with
the appropriate __init__.py hierarchy) and import them, for tests that need
live module objects to introspect.
create_module ¶
create_module() -> Callable[[Path], ModuleType]
Return a callable that creates and imports an empty Python module.
Returns:
| Type | Description |
|---|---|
Callable[[Path], ModuleType]
|
A callable that creates an empty module file and imports it, |
Callable[[Path], ModuleType]
|
initializing any missing parent directories as a package hierarchy |
Callable[[Path], ModuleType]
|
first. |
Source code in src/pyrig_fixtures/rig/tests/fixtures/modules.py
create_package ¶
create_package() -> Callable[[Path], ModuleType]
Return a callable that creates and imports an empty Python package.
Returns:
| Type | Description |
|---|---|
Callable[[Path], ModuleType]
|
A callable that creates a directory tree as an empty package |
Callable[[Path], ModuleType]
|
hierarchy and imports the deepest package. |
Source code in src/pyrig_fixtures/rig/tests/fixtures/modules.py
create_source_package ¶
create_source_package(
tmp_source_root_path: Path,
create_package: Callable[[Path], ModuleType],
) -> Callable[[Path], ModuleType]
Return a callable that creates and imports a package under the source root.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
tmp_source_root_path
|
Path
|
Temporary source root directory that paths passed to the returned callable are resolved against. |
required |
create_package
|
Callable[[Path], ModuleType]
|
Fixture that creates and imports a package. |
required |
Returns:
| Type | Description |
|---|---|
Callable[[Path], ModuleType]
|
A callable that creates an empty package under the temporary source |
Callable[[Path], ModuleType]
|
root and imports it. |
Source code in src/pyrig_fixtures/rig/tests/fixtures/modules.py
paths ¶
Fixtures for building a temporary project/source/package directory tree.
Provides an empty, disposable instance of this ecosystem's conventional src layout (project root → source root → package root), so tests can exercise path-sensitive logic without touching the real project on disk.
tmp_package_root_path ¶
tmp_package_root_path(
tmp_project_root_path: Path,
tmp_source_root_path: Path,
create_source_package: Callable[[Path], ModuleType],
) -> tuple[Path, ModuleType]
Provide the temporary package root, already created and imported as a package.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
tmp_project_root_path
|
Path
|
Temporary project root directory. |
required |
tmp_source_root_path
|
Path
|
Temporary source root directory. |
required |
create_source_package
|
Callable[[Path], ModuleType]
|
Callable that creates and imports a package at a path relative to the temporary source root. |
required |
Returns:
| Type | Description |
|---|---|
Path
|
Tuple of |
ModuleType
|
the temporary source root, and its imported package module. |
Source code in src/pyrig_fixtures/rig/tests/fixtures/paths.py
tmp_project_root_path ¶
Provide a temporary project root directory named after the current project.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
tmp_path
|
Path
|
Pytest's per-test temporary directory. |
required |
Returns:
| Type | Description |
|---|---|
Path
|
Path to the temporary project root directory, already created on disk. |
Source code in src/pyrig_fixtures/rig/tests/fixtures/paths.py
tmp_source_root_path ¶
Provide a temporary source root directory nested inside the project root.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
tmp_project_root_path
|
Path
|
Temporary project root directory. |
required |
Returns:
| Type | Description |
|---|---|
Path
|
Path to the temporary source root directory, already created on disk. |