Skip to content

Commit

Permalink
Fix pickling when pytest is loaded.
Browse files Browse the repository at this point in the history
Older versions of pytest will add a "None" module to sys.modules.
  • Loading branch information
QuLogic committed Jul 25, 2017
1 parent eb49847 commit f2269de
Showing 1 changed file with 2 additions and 1 deletion.
3 changes: 2 additions & 1 deletion cloudpickle/cloudpickle.py
Original file line number Diff line number Diff line change
Expand Up @@ -384,7 +384,8 @@ def _save_subimports(self, code, top_level_dependencies):
# check if the package has any currently loaded sub-imports
prefix = x.__name__ + '.'
for name, module in sys.modules.items():
if name.startswith(prefix):
# Older versions of pytest will add a "None" module to sys.modules.
if name is not None and name.startswith(prefix):
# check whether the function can address the sub-module
tokens = set(name[len(prefix):].split('.'))
if not tokens - set(code.co_names):
Expand Down

0 comments on commit f2269de

Please sign in to comment.