On Sat, 2009-09-26 at 18:19 +0200, holger krekel wrote: > On Sat, Sep 26, 2009 at 18:05 +0200, Ronny Pfannschmidt wrote: > > On Sat, 2009-09-26 at 17:02 +0200, holger krekel wrote: > > > Hi Ronny, > > > > > > > i wonder what would be a good way to test the handling of unimportable > > > > modules or fallbacks for missing modules. > > > > i don't have any initial idea on how to get started with that. > > > > > > what i usually do is to provide the to-be-unimportable module > > > but put e.g. "raise ImportError()" into it. Using the 'tmpdir' > > > and 'monkeypatch' funcargs makes it easy to do this, e.g.: > > > > > > def test_unimportable(tmpdir, monkeypatch): > > > tmpdir.join("docutils.py").write("raise ImportError()") > > > monkeypatch.setattr(sys, 'path', [str(tmpdir)] + sys.path) > > > > > > ..call-and-assert.. > > > > unfortunately that doesnt help with modules that are already imported > > unless of course i use something like propper process based sandboxing > > for all tests (and i'd like to avoid that) > > yes, either requires running things in a new process or hacking > 'sys.modules' as well - which you could all do through a nice funcarg. > you are right, a funcarg is on the wayfor simple cases, and im starting to see execnet as good way to wire up the more complex cases
_______________________________________________ py-dev mailing list py-dev@codespeak.net http://codespeak.net/mailman/listinfo/py-dev