[py-dev] how to test fallbacks for missing modules?
Ronny Pfannschmidt
Ronny.Pfannschmidt at gmx.de
Sat Sep 26 18:05:31 CEST 2009
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)
More information about the Pytest-dev
mailing list