[TIP] Patching __import__
kumar.mcmillan at gmail.com
Tue May 24 11:38:45 PDT 2011
On Tue, May 24, 2011 at 1:16 PM, Michael Foord <michael at voidspace.org.uk> wrote:
> Right, but the point is that using patch.dict *isn't* an import hook. It
> only adds (and then removes or restores) that entry from the sys.modules
> dict when the decorated test is executed.
> *However*, it does get a reference to the sys.modules dictionary at import
> time (to know which dictionary to patch) - and as the problem is happening
> you're probably right about why. It's just that getting a reference to
> sys.modules is not unusual in Python code, so I don't think it is "playing
> with fire". It is a very odd interaction.
Yeah, it definitely should be possible to munge sys.modules without
ill effects. If you can pinpoint it in Nose, please file a bug :)
I haven't fully thought it through but you might be able to implement
this feature cleaner as an actual import hook.
> All the best,
> Michael Foord
>> You could try:
>> nosetests --debug=nose.importer,nose.inspector,nose.selector
>> to see if that gives you some clues before / after commenting out the
>> @patch.dict line. You could also try:
>> nosetests --no-path-adjustment
>> to turn off the import hooks.
>>> Tried to debug it a bit but no luck...
>>> Any ideas?
>>> testing-in-python mailing list
>>> testing-in-python at lists.idyll.org
>> testing-in-python mailing list
>> testing-in-python at lists.idyll.org
> May you do good and not evil
> May you find forgiveness for yourself and forgive others
> May you share freely, never taking more than you give.
> -- the sqlite blessing http://www.sqlite.org/different.html
More information about the testing-in-python