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_docsguards check and the.gitdirectory 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.solve_destructive_options(config)[source]¶
Solve the destructive options to determine which tests to run.
- 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.
- 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
runnerfixture pinsHOME(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/.rustupand 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
mpmconfiguration from the test suite.Any
config.tomlin the host configuration folder bleeds into every in-process CLI invocation: a localcpan = false, for instance, silently drops the manager from the default selection, socheck_manager_selectionassertions 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 repointsclick.get_app_dir()-based config discovery at a fresh empty directory.HOMEis 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.configbindsget_app_dirat import, out of the reach of this fixture. A test driving that pre-load patchesmeta_package_manager.config.get_app_diritself.
- tests.conftest.run_as_regular_user(monkeypatch)[source]¶
Make
mpmsee a regular user, even when the suite runs as root.As root,
mpmdrops the privilege escalator from every command, so a test that expects asudo,doasorrun0prefix passes only for a regular user. A container build runs the suite as root, likeabuild -Fdoes. A test of the root case patchesos.geteuiditself, 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_OPTandPERL_LOCAL_LIB_ROOTfrom a shell startup file. Either one turns on the local::lib rule ofcpan, which then keeps only the modules of that directory: a test replaying a documentedcpan -Owould list nothing on such a machine. A test of the rule sets the variables itself.
- tests.conftest.stub_run_cli(monkeypatch)[source]¶
Replace a manager’s
run_cliwith a canned-output stub.Returns a
stub(manager, output)callable: everyrun_clicall onmanagerthen returnsoutputwithout spawning a subprocess. The workhorse of the output-parsing tests (test_manager_*). To assert on the arguments a manager builds instead, seecapture_run_cli().
- tests.conftest.capture_run_cli(monkeypatch)[source]¶
Replace a manager’s
run_cliwith 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_managerswith a generator yielding itsfake, mirroring the runtime knobs (timeout, stop_on_error, dry_run, plan) that_select_managerswould 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 throughpool.get()(like the bar-plugin renderer’s upgrade-CLI augmentation), and de-registers it at teardown. Both steps go throughadd_manager()andremove_manager(), which evict the pool’s cached ID lists: a fake left inall_manager_idsafter its test crashes the next test recomputingmaintained_manager_idsfrom it.Any
peershanded 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
outdatedexceeds--timeout.It is a
TimingOutFakeManager.Use only for tests that need to verify
meta_package_manager.execution.CLIExecutor.run()catchessubprocess.TimeoutExpiredand 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
installedandsearchthrough a command, as a real manager does.The fixture patches the two queries of
ChangingFakeManager.--dry-runsimulates that command, where--planruns it.