Page MenuHomeDevCentral

Avoid importlib.machinery.SourceFileLoader load_module use
ClosedPublic

Authored by dereckson on Sep 17 2025, 16:42.
Tags
None
Referenced Files
F12440473: D3685.id9536.diff
Thu, Nov 6, 11:17
F12440207: D3685.diff
Thu, Nov 6, 10:57
F12437061: D3685.id9535.diff
Thu, Nov 6, 04:28
F12436392: D3685.id.diff
Thu, Nov 6, 03:24
F12434877: D3685.diff
Thu, Nov 6, 00:25
F12434252: D3685.id9535.diff
Wed, Nov 5, 22:31
F12433629: D3685.id9535.diff
Wed, Nov 5, 21:19
F12431642: D3685.id9724.diff
Wed, Nov 5, 16:55
Subscribers
None

Details

Summary

Currently, unit tests for Salt module and for scripts used the SourceFileLoader
class to manually load a specific script. The class load_module() method has
been deprecated for a while and won't be available in Python 3.12+.

Instead, we now use two strategies to import Python code:

  • treat _modules/ as a package folder by passing the path as PYTHONPATH
  • still use importlib for scripts, with compatible code

To import scripts directly with import can be a challenge, as roles like
"paas-docker" use dashes. The scripts filenames themselves contain dashes.

This fixes the following issue:
<frozen importlib._bootstrap>:283: DeprecationWarning: the load_module() method
is deprecated and slated for removal in Python 3.12; use exec_module() instead

Test Plan

On the T2123-improve-tests-suite branch to avoid distractions, make test
show every test pass without the deprecation warning.

Diff Detail

Repository
rOPS Nasqueron Operations
Lint
Lint Passed
Unit
No Test Coverage
Branch
T2123-improve-tests-suite
Build Status
Buildable 5902
Build 6184: arc lint + arc unit