From f2269def6d3b2d8c831e66f3c56b73bafe903dc2 Mon Sep 17 00:00:00 2001 From: Elliott Sales de Andrade Date: Mon, 10 Jul 2017 04:55:55 -0400 Subject: [PATCH] Fix pickling when pytest is loaded. Older versions of pytest will add a "None" module to sys.modules. --- cloudpickle/cloudpickle.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/cloudpickle/cloudpickle.py b/cloudpickle/cloudpickle.py index f0114ad1f..24fe65fe6 100644 --- a/cloudpickle/cloudpickle.py +++ b/cloudpickle/cloudpickle.py @@ -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):