【问题标题】:Skip test depending on platform根据平台跳过测试
【发布时间】:2017-03-14 09:06:34
【问题描述】:

有没有办法根据platform 跳过单元测试?我有 linux 特定的鼻子测试,它们只使用 linux 库,我想在我们的 mac 构建中跳过。

【问题讨论】:

    标签: nose


    【解决方案1】:

    显然,你是这样做的

    第一步,创建一个装饰器

    def skip_if(condition):
        """Conditionally skips a test"""
        def wrapper(f):
            f.__test__ = not condition
            return f
    
        return wrapper
    

    第二步,在你的情况下使用sys.platform

    import sys
    @skip_if(sys.platform == "linux")
    def test_linux_only()
        linus_torvalds()
    

    【讨论】:

      猜你喜欢
      • 2023-03-02
      • 1970-01-01
      • 2021-07-02
      • 2019-04-30
      • 1970-01-01
      • 2021-07-15
      • 1970-01-01
      • 2021-10-18
      • 1970-01-01
      相关资源
      最近更新 更多