【问题标题】:What is the difference between Python's unittest and unittest2 modules?Python 的 unittest 和 unittest2 模块有什么区别?
【发布时间】:2016-04-23 21:50:35
【问题描述】:

我目前正在处理一些使用 unittest2 模块的代码。我怀疑这段代码是为 python2 设计的。可以使用 python3 unittest 作为 unittest2 的替代品吗?两者有什么区别?

【问题讨论】:

    标签: python-3.x compatibility python-2.x python-module python-unittest


    【解决方案1】:

    根据Python 2.7 unittest docs

    unittest2:Python 2.4-2.6 的新单元测试功能的反向移植 Python 2.7 中的 unittest 添加了新功能,包括测试 发现。 unittest2 允许您在早期使用这些功能 Python 版本。

    因此,从 Python 2 下的 unittest2 移动到 Python 2.7 或 Python 3 下的 unittest 应该完全符合您的要求

    【讨论】:

    • unittest2 似乎也支持unittest 不支持的一些高级功能。例如,subTestPython3.4 支持。
    猜你喜欢
    • 2014-07-03
    • 2011-12-18
    • 2010-10-17
    • 2011-03-01
    • 2011-04-10
    • 2013-01-11
    • 2015-11-25
    • 2023-03-28
    相关资源
    最近更新 更多