【问题标题】:Unittests marked with @unittest.skip are not marked under nosetests标有@unittest.skip 的单元测试没有在nosetests 下标记
【发布时间】:2014-08-10 12:14:36
【问题描述】:

当使用@unittest.skip 运行测试时,一般被跳过的测试用小s标记,最后上报tally。

如果我用鼻子测试运行测试,测试就会消失,最终报告中不会留下任何存在的痕迹。我尝试了 --no-skip,但它没有改变任何东西。

如何在鼻子下跑时跳过“s”标记和总数?

【问题讨论】:

  • 你有 41.6k 的代表,但正确的答案没有这样标记?
  • @Clintm:我有 41.6k 代表,但我一整天都没有花在 SO 上?

标签: python-3.x nose python-unittest


【解决方案1】:

看来您必须提供跳过测试的理由:

from unittest import skip

@skip
def foo_test():
    pass

给出你观察到的:

----------------------------------------------------------------------
Ran 0 tests in 0.000s

OK

同时:

from unittest import skip

@skip("nose likes having good reasons")
def foo_test():
    pass

会给你:

foo_test.foo_test ... SKIP: nose likes having good reasons

----------------------------------------------------------------------
Ran 1 test in 0.003s

OK (SKIP=1)

【讨论】:

    【解决方案2】:

    我通过@nottest 装饰器(在测试方法级别)在nose 中将要跳过的测试标记为S,并列在跳过的测试数量中结束。

    为了得到你导入的装饰器:

    from nose.tools import nottest
    

    【讨论】:

    • 没有办法与标记为 unittest.skip 的结果相同?
    • 看起来@Oleksiy 提供了有关它无法与unittest.skip 合作的原因的信息。我一直将@nottestunittest-extended 鼻子测试结合使用,但如果您已经在使用unittest.skip,那么尝试保留它是有意义的。
    猜你喜欢
    • 2023-03-17
    • 1970-01-01
    • 1970-01-01
    • 2017-12-07
    • 2021-01-10
    • 2023-01-09
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多