Skip to content

test(slm): four executor tests fail when run alone — they stub services as a MagicMock, which is not a package #20746

Open

Description

@mrveiss

Problem

Four SLM tests load services/playbook_executor.py by file path, after stubbing sys.modules["services"] with a MagicMock. Run on their own, three fail to collect and one fails:

Test file Run alone
tests/services/test_self_update_systemd_detach_11492.py 1 error at collection
tests/services/test_dynamic_inventory_group_vars_11781.py 1 error at collection
tests/services/test_wizard_inventory_parity_14286.py 1 error at collection
tests/services/test_extra_vars_file_11735.py 3 failed, 2 passed

The error is ModuleNotFoundError: No module named 'services.git_failure'; 'services' is not a package. A MagicMock has no real __path__, so any services.* module the executor imports that isn't in the stub list can't load. The executor has gained such imports over time (services.git_failure, services.playbook_code_source_gate, and others).

Whether they pass in the full suite depends on whether an earlier test already imported those modules. Their result therefore depends on test order.

Fix

Use one shared loader for these tests that leaves the real services package in place and stubs only the modules that reach the network or the DB. tests/test_no_restart_sync_20743.py (#20743) does this already. Alternatively, stub services as a real types.ModuleType with a __path__.

Acceptance criteria

  • Each of the four files passes when run on its own.
  • They share one loader instead of four copies of the stub list.

Found while working on #20743.

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't workingphase:M1.4Wizard and SLM: choose a mode, apply it, default models workpriority: mediumtesting

    Projects

    No projects

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions