一键导入
leapp-unit-tests
Write or fix unit tests for leapp-repository actors and shared libraries. Covers test placement, mocking patterns, and project conventions.
用 Codex 或 Claude 帮你安装 复制这段 Prompt,粘贴到 Codex、Claude 或其他助手里,让它检查 Skill 页面并帮你完成安装。
菜单
Write or fix unit tests for leapp-repository actors and shared libraries. Covers test placement, mocking patterns, and project conventions.
用 Codex 或 Claude 帮你安装 复制这段 Prompt,粘贴到 Codex、Claude 或其他助手里,让它检查 Skill 页面并帮你完成安装。
基于 SOC 职业分类
Develop or modify leapp-repository actors. Covers actor structure, phase selection, placement rules, and key constraints.
Run tests and linters for leapp-repository. Covers container-based CI testing, single-actor fast tests, and lint commands.
| name | leapp-unit-tests |
| description | Write or fix unit tests for leapp-repository actors and shared libraries. Covers test placement, mocking patterns, and project conventions. |
Tests live in the tests directory under an actor:
repos/system_upgrade/<leapp_repo_dir>/actors/<actor_name>/
├── actor.py
├── libraries/<actor_name>.py
└── tests/test_<actor_name>.py # <-- tests go here
Tests for shared libraries are in the tests sub-directory next to the shared library, like:
repos/system_upgrade/<leapp_repo_dir>/
├── <libA>.py
├── tests/test_<libA>.py # <-- tests for libA go here
├── <pathB>/<libB>.py
└── <pathB>/tests/test_<libB>.py # <-- tests for libB go here
As mocked objects, use functions and classes present in leapp.libraries.common.testutils - especially:
| Utility | Purpose |
|---|---|
CurrentActorMocked(...) | Mock api.current_actor with configuration, version, etc. |
produce_mocked() | Capture api.produce(...) calls for assertions |
create_report_mocked() | Capture reporting.create_report(...) calls |
logger_mocked() | Capture log output |
Test the library, not the actor class directly:
from leapp.libraries.actor import <actor_lib>
from leapp.libraries.common.testutils import CurrentActorMocked, produce_mocked
from leapp.libraries.stdlib import api
from leapp.models import <ConsumedModel>, <ProducedModel>
def test_<scenario>(monkeypatch):
# 1. Mock current_actor context
monkeypatch.setattr(api, 'current_actor', CurrentActorMocked())
# 2. Mock consumed messages
monkeypatch.setattr(api, 'consume', lambda x: iter([<ConsumedModel>(...)]))
# 3. Mock produce
monkeypatch.setattr(api, 'produce', produce_mocked())
# 4. Call library function
<actor_lib>.process()
# 5. Assert on produced messages
assert api.produce.called
assert isinstance(api.produce.model_instances[0], <ProducedModel>)
Test the library, not actor.py — the process() method should be a thin wrapper.
Pass consumed messages via CurrentActorMocked(msgs=[...]).
Mock file I/O instead of creating temp files when possible. Use the leapp_tmpdir fixture when tempfiles are needed.
Use monkeypatch.setattr over unittest.mock.patch — monkeypatch is the project convention.
Cover at least: happy path, edge/error cases, and inhibitor conditions if applicable.
If you intentionally skip a test scenario, add a comment explaining why.
Use consistent string quoting within a file.
Use pytest.mark.parametrize where possible.
Never use type() when creating mock classes.
Use module-level constants with "_" prefix.
Name test functions clearly after the behavior: test_inhibits_when_fips_enabled not test_fips_1.
Look at existing tests in repos/system_upgrade/common/actors/ for project conventions before writing new ones.
See skills/leapp-test-runner/ for full commands. Quick single-actor run:
ACTOR=<actor_name> make dev_test_no_lint