Skip to content

DeprecationWarning: the load_module() method is deprecated and slated for removal in Python 3.12; use exec_module() instead - #2576

Merged
cyberw merged 2 commits into
locustio:masterfrom
mgor:bug/load_module_deprecated
Feb 5, 2024
Merged

DeprecationWarning: the load_module() method is deprecated and slated for removal in Python 3.12; use exec_module() instead#2576
cyberw merged 2 commits into
locustio:masterfrom
mgor:bug/load_module_deprecated

Conversation

@mgor

@mgor mgor commented Feb 1, 2024

Copy link
Copy Markdown
Contributor

When running the unit tests and looking at the output, the DeprecationWarning in the title is thrown/visible a couple of times.

In python 3.4 load_module was replaced with exec_module. [0][1]

Deprecated since version 3.4: The recommended API for loading a module is exec_module() (and create_module()). Loaders should implement it instead of load_module(). The import machinery takes care of all the other responsibilities of load_module() when exec_module() is implemented.

The tests does indeed work on 3.12, so seems like it hasn't been removed yet,
but this PR replaces the call to load_module in locust.util.load_locustfile.load_locustfile to use exec_module instead.

[0] https://peps.python.org/pep-0451/
[1] https://docs.python.org/3/library/importlib.html#importlib.abc.Loader.load_module

mgor added 2 commits February 1, 2024 13:48
instead of `load_module`, which is deprecated and was planned to be removed in 3.12.
@cyberw

cyberw commented Feb 1, 2024

Copy link
Copy Markdown
Collaborator

Awesome. I've been annoyed by this for a long time. Will sure to merge this once the modern-UI-default is released.

@cyberw
cyberw merged commit ba189b1 into locustio:master Feb 5, 2024
cyberw added a commit that referenced this pull request Feb 6, 2024
…odule during import, but it can be worked around (this used to work before #2576)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants