【问题标题】:How to write unittest for a module which is only supported in Python >(3,0) while the rest are supported across all the version?如何为仅在 Python >(3,0) 中受支持的模块编写单元测试,而所有版本都支持其余模块?
【发布时间】:2019-09-14 17:50:04
【问题描述】:

如果测试在python < (3,0) 中运行,我想排除运行某些单元测试。我尝试使用@unittest.skipIf 跳过测试类。测试被排除在外,但导入语句仍会执行,这会导致导入错误,因为如果 python < (3,0) 未安装用于模块的某些库。

【问题讨论】:

    标签: python unit-testing


    【解决方案1】:

    您可以使用以下内容:

    import sys
    if sys.version_info[0] < 3:
        # unitests
    

    这将检查 python 版本,只有当那个 python 版本是你想要的它才会运行。

    【讨论】:

      猜你喜欢
      • 2018-01-26
      • 2012-02-20
      • 1970-01-01
      • 1970-01-01
      • 2014-06-24
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2015-04-24
      相关资源
      最近更新 更多