tests.conftest module¶

Fixtures, configuration and helpers for tests.

tests.conftest.PROJECT_ROOT = PosixPath('/home/runner/work/meta-package-manager/meta-package-manager')¶

Repository root, holding the committed artifacts the test_docs guards check and the .git directory whose presence marks a developer checkout.

tests.conftest.pytest_addoption(parser)[source]¶

Add custom command line options.

Based on Pytest’s documentation examples.

By default, runs non-destructive tests and skips destructive ones.

tests.conftest.pytest_configure(config)[source]¶

Register custom markers.

tests.conftest.solve_destructive_options(config)[source]¶

Solve the destructive options to determine which tests to run.

Return type:

tuple[bool, bool]

tests.conftest.pytest_collection_modifyitems(config, items)[source]¶

Apply collection-time markers and skips.

On top of the command-line destructive-test selection, this classifies the integration layer and quarantines the repo-maintenance guards, so a downstream packager can run the suite with a single selection and no per-module ignore list. See https://mpm.run/packaging/

tests.conftest.pytest_report_header(config, start_path)[source]¶

Display destructive options status in test report header.

Return type:

tuple[str, ...]

tests.conftest.warm_manager_probes()[source]¶

Resolve every pool manager’s availability before the first test runs.

The pool is a module-global singleton shared by every test of the process, and a manager’s version probe caches its first result on the instance. The click-extra runner fixture pins HOME (and its platform equivalents) to an empty directory for the duration of each CLI invocation, so a probe first fired from inside a test spawns into a crippled environment: the GitHub runners’ rustup shim at ~/.cargo/bin/cargo, for one, cannot resolve a toolchain without $HOME/.rustup and answers with an error instead of a version, caching cargo as unavailable for every later test on that worker. Warming the whole pool here, before any test and outside any runner isolation, seeds those caches from the real environment.

A session fixture rather than a collection-time probe, because a probe that answers differently on two xdist workers leaves them with diverging parametrize lists and aborts the session. Running after collection keeps the workers agreeing on the test list, and once per worker keeps the cost to one pass.

Not routed through warm_availability(), which sizes its thread pool from the active click context: a pytest session has none, so that helper returns before probing anything. The lane grouping it relies on is reused directly instead, since managers sharing a version probe must still take turns rather than spawn the same command at once.

Threaded because a probe is a subprocess wait rather than work: sequentially it cost up to 69 seconds of every worker’s startup on the slower runners, enough to show up in the suite’s own slowest-tests report.

tests.conftest.isolate_user_config(isolated_app_dir)[source]¶

Hide the developer’s real mpm configuration from the test suite.

Any config.toml in the host configuration folder bleeds into every in-process CLI invocation: a local cpan = false, for instance, silently drops the manager from the default selection, so check_manager_selection assertions that expect the full default set fail locally while passing in CI, which has no such file.

Autouse alias of click-extra’s isolated_app_dir() fixture, which repoints click.get_app_dir()-based config discovery at a fresh empty directory. HOME is left intact so the integration layer keeps detecting the real package managers, and the override does not propagate to subprocesses. Tests that exercise config loading pass --config <path> explicitly, which bypasses the default search pattern and is therefore left untouched.

The eager pre-load of main() escapes it: meta_package_manager.config binds get_app_dir at import, out of the reach of this fixture. A test driving that pre-load patches meta_package_manager.config.get_app_dir itself.

tests.conftest.run_as_regular_user(monkeypatch)[source]¶

Make mpm see a regular user, even when the suite runs as root.

As root, mpm drops the privilege escalator from every command, so a test that expects a sudo, doas or run0 prefix passes only for a regular user. A container build runs the suite as root, like abuild -F does. A test of the root case patches os.geteuid itself, which takes precedence for its duration.

The patch stays in the test process: a subprocess sees the real user.

tests.conftest.isolate_local_lib(monkeypatch)[source]¶

Hide the developer’s local::lib from the test suite.

local::lib exports PERL_MM_OPT and PERL_LOCAL_LIB_ROOT from a shell startup file. Either one turns on the local::lib rule of cpan, which then keeps only the modules of that directory: a test replaying a documented cpan -O would list nothing on such a machine. A test of the rule sets the variables itself.

tests.conftest.invoke(runner)[source]¶
tests.conftest.stub_run_cli(monkeypatch)[source]¶

Replace a manager’s run_cli with a canned-output stub.

Returns a stub(manager, output) callable: every run_cli call on manager then returns output without spawning a subprocess. The workhorse of the output-parsing tests (test_manager_*). To assert on the arguments a manager builds instead, see capture_run_cli().

tests.conftest.capture_run_cli(monkeypatch)[source]¶

Replace a manager’s run_cli with a positional-argument recorder.

Returns a capture(manager, output="") callable, which patches the manager and hands back the list every call’s positional arguments are appended to, so a test can assert on the exact CLI the manager builds.

tests.conftest.patch_pool_with(monkeypatch, request)[source]¶

Return a function installing a fake manager into the pool for one test.

The function replaces pool.select_managers with a generator yielding its fake, mirroring the runtime knobs (timeout, stop_on_error, dry_run, plan) that _select_managers would forward, so the CLI exercises the same code path it does against real managers. It also registers the fake in the pool, for the code paths re-resolving a manager from its ID through pool.get() (like the bar-plugin renderer’s upgrade-CLI augmentation), and de-registers it at teardown. Both steps go through add_manager() and remove_manager(), which evict the pool’s cached ID lists: a fake left in all_manager_ids after its test crashes the next test recomputing maintained_manager_ids from it.

Any peers handed after the fake are selected and registered with it, in that order, for a test that needs several managers in one run. The function still returns the first fake.

tests.conftest.fake_pool(patch_pool_with)[source]¶

Yield a single deterministic fake manager from the pool.

It is a FakeManager.

Use for CLI plumbing tests (stats lines, table rendering, exit codes) that need a stable package set regardless of host PATH.

tests.conftest.slow_fake_pool(patch_pool_with)[source]¶

Yield a fake manager whose outdated exceeds --timeout.

It is a TimingOutFakeManager.

Use only for tests that need to verify meta_package_manager.execution.CLIExecutor.run() catches subprocess.TimeoutExpired and logs the expected warning.

tests.conftest.changing_fake_pool(patch_pool_with)[source]¶

Yield a fake manager whose inventory changes when a command acts on it.

It is a ChangingFakeManager.

Use for the tests of the change report closing the commands that install, remove or upgrade packages.

tests.conftest.queries_through_a_cli(monkeypatch)[source]¶

Answer installed and search through a command, as a real manager does.

The fixture patches the two queries of ChangingFakeManager.

--dry-run simulates that command, where --plan runs it.

tests.conftest.subcmd()[source]¶

Set the subcommand arguments in all CLI calls of test_cli_*.py files.

Must returns a string or an iterable of strings. Defaults to None, which allows tests relying on this fixture to selectively skip running.