[issue21600] mock.patch.stopall doesn't work with patch.dict to sys.modules

Eric Snow report at bugs.python.org
Thu Dec 11 04:52:13 CET 2014


Eric Snow added the comment:

At least for CPython sys.modules is initially set to the modules dict on the interpreter struct.  As of 3.4 the import system itself only cares about sys.modules (I'll have to double check on builtin___import__).  However, if I recall correctly at least part of the import C-API interacts directly with the original interpreter copy of the modules dict.

The catch is that setting sys.modules to something else does not also change the dict on the interpreter struct.  So they will be out of sync.  This may cause problems.  In practice I don't think it's a big deal, but there is no guarantee that patching out sys.modules will give you the behavior that you expect.

See also issue #12633.

----------

_______________________________________
Python tracker <report at bugs.python.org>
<http://bugs.python.org/issue21600>
_______________________________________


More information about the Python-bugs-list mailing list