python - IPython 和单元测试,固定测试不显示为固定

标签 python unit-testing ipython

我刚刚开始使用 IPython。我非常喜欢它,并且期待使用 %run 魔术方法来运行单元测试而无需退出 shell。所以我尝试了:

In [30]: run runTests.py

据我所知,它运行得很好,按照我在 runTests.py 文件中描述的方式运行测试。然而,输出显示我的测试失败了:

Ran 16 tests in 0.156s

FAILED (failures=3)

因此,我深入研究代码并解决了问题,然后返回 IPython 再次运行测试:

In [31]: run runTests.py

但是,这报告说我的测试仍然失败:

Ran 16 tests in 0.141s

FAILED (failures=3)

在 IPython 之外运行测试表明我实际上已经修复了它们。 IPython 文档似乎指出,每当我使用 %run 时,都应该反射(reflect)出对代码的任何更改:

The %run magic command allows you to run any python script and load all of its data directly into the interactive namespace. Since the file is re-read from disk each time, changes you make to it are reflected immediately.

所以我的问题是,什么给出了?我的测试导入的模块是否加载到 IPython 中重要吗?我尝试了autoreload,但这也没有帮助。我希望能够从 IPython 快速运行我的单元测试,因此我将不胜感激有关最佳方法的任何指示。

最佳答案

是的,我想这是因为您导入的模块在运行之间不会重新加载。

自动重新加载应该有助于解决这个问题。阅读 the docs并检查您是否正确使用它。请注意,它无法重新加载已编译的 C 扩展。当然,自动重新加载可能有错误,所以如果您确信自己做得正确,请询问 the mailing listfile a bug .

关于python - IPython 和单元测试,固定测试不显示为固定,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9811324/

相关文章:

Python3.5-pip安装错误: Unable to find vcvarsall. bat

ipython - 可以在jupyter单元函数上运行python doctest吗?

python - 加载 IPython 笔记本时出错

python - latex 故障 ipython daft matplotlib

python - 请求无法在同一个 Flask 应用程序中调用多个路由

python - 以交互模式加载模块变量

python - 如何列出所有未使用的 Jenkins 插件?

reactjs - React Native + Jest + enzyme : Why does Enzyme not recognize some components?

unit-testing - 自动化单元测试可以代替静态类型检查吗?

java - 乘以 AssertJ 断言中设置的条件?