在doctest(Python)中模拟(从X导入Y)的Y [英] Mock Y of (from X import Y) in doctest (python)

查看:81
本文介绍了在doctest(Python)中模拟(从X导入Y)的Y的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试使用驻留在单独模块中的模拟功能创建doctest 并作为波纹管导入

I'm trying to create a doctest with mock of function that resides in a separate module and that is imported as bellow

from foomodule import foo

def bar():
    """
    >>> from minimock import mock
    >>> mock('foo', nsdicts=(bar.func_globals,), returns=5)
    >>> bar()
    Called foo()
    10
    """
    return foo() * 2


import doctest
doctest.testmod()

foomodule.py:

foomodule.py:

def foo():
    raise ValueError, "Don't call me during testing!"

这失败.

如果我将导入更改为 import foomodule 并在任何地方使用 foomodule.foo 然后就可以了.

If I change import to import foomodule and use foomodule.foo everywhere Then it works.

但是对于以上述方式导入的模拟函数有什么解决方案吗?

But is there any solution for mocking function imported the way above?

推荐答案

最后,发现这实际上是MiniMock的主干版本问题. 老马stable的表现如预期.

Finally, found out that this was rather an issue of trunk version of MiniMock. Old stable one performs as expected.

这篇关于在doctest(Python)中模拟(从X导入Y)的Y的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆