Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

recreate_module: set __spec__ to the new module #7773

Merged
merged 2 commits into from
Sep 24, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions celery/local.py
Original file line number Diff line number Diff line change
Expand Up @@ -517,6 +517,7 @@ def recreate_module(name, compat_modules=None, by_module=None, direct=None,
new_module.__dict__.update({
mod: get_compat_module(new_module, mod) for mod in compat_modules
})
new_module.__spec__ = old_module.__spec__
return old_module, new_module


Expand Down
14 changes: 14 additions & 0 deletions t/unit/utils/test_local.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
import sys
from importlib.util import find_spec
from unittest.mock import Mock

import pytest
Expand Down Expand Up @@ -339,3 +341,15 @@ def test_maybe_evaluate(self):

assert maybe_evaluate(30) == 30
assert x.__evaluated__()


class test_celery_import:
def test_import_celery(self, monkeypatch):
monkeypatch.delitem(sys.modules, "celery", raising=False)
spec = find_spec("celery")
assert spec

import celery

assert celery.__spec__ == spec
assert find_spec("celery") == spec