Page MenuHomeDevCentral

Avoid importlib.machinery.SourceFileLoader load_module use
ClosedPublic

Authored by dereckson on Sep 17 2025, 16:42.
Tags
None
Referenced Files
F19178688: D3685.id9537.diff
Thu, Dec 25, 04:34
F19172489: D3685.id9537.diff
Thu, Dec 25, 03:19
F19164564: D3685.id9537.diff
Thu, Dec 25, 01:38
F19164521: D3685.diff
Thu, Dec 25, 01:34
F19160709: D3685.id9724.diff
Thu, Dec 25, 00:31
F19147428: D3685.id9724.diff
Wed, Dec 24, 21:30
F19140201: D3685.diff
Wed, Dec 24, 19:55
F19140166: D3685.id9535.diff
Wed, Dec 24, 19:53
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 Errors
SeverityLocationCodeMessage
Error_tests/helpers.py:11E303flake8 E303
Error_tests/modules/test_convert.py:8E302flake8 E302
Unit
No Test Coverage
Branch
T2123-improve-tests-suite
Build Status
Buildable 5901
Build 6183: arc lint + arc unit