Skip to content

Commit 95fc4cf

Browse files
committed
Add dynamic module loading fix for dataclasses
1 parent 324ce85 commit 95fc4cf

File tree

1 file changed

+6
-0
lines changed

1 file changed

+6
-0
lines changed

resources/unittest_template.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,12 @@ def _load_user_module(result_writer, exit_wrapper: _EXIT_WRAPPER_TYPE) -> Module
5252
exit_wrapper(5)
5353

5454
_module = ModuleType("module")
55+
# It's necessary to manually add the module to the sys modules
56+
# Dataclasses do not add themselves which causes issues for us with this type of dynamic loading
57+
# if from __future__ import annotations is also used
58+
# See: https://github.com/mkdocs/mkdocs/issues/3141 and https://github.com/sqlalchemy/alembic/issues/1419
59+
sys.modules[_module.__name__] = _module
60+
5561
exec(code, _module.__dict__)
5662

5763
return _module

0 commit comments

Comments
 (0)