Skip to content

Commit e6de4f4

Browse files
QuLogicrgbkrk
authored andcommitted
Fix pickling when pytest is loaded.
Older versions of pytest will add a "None" module to sys.modules.
1 parent eb49847 commit e6de4f4

File tree

1 file changed

+2
-1
lines changed

1 file changed

+2
-1
lines changed

cloudpickle/cloudpickle.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -384,7 +384,8 @@ def _save_subimports(self, code, top_level_dependencies):
384384
# check if the package has any currently loaded sub-imports
385385
prefix = x.__name__ + '.'
386386
for name, module in sys.modules.items():
387-
if name.startswith(prefix):
387+
# Older versions of pytest will add a "None" module to sys.modules.
388+
if name is not None and name.startswith(prefix):
388389
# check whether the function can address the sub-module
389390
tokens = set(name[len(prefix):].split('.'))
390391
if not tokens - set(code.co_names):

0 commit comments

Comments
 (0)