【问题标题】:Run skipped tests by nosetest (no-skip doesn't work)通过nosetest 运行跳过的测试(no-skip 不起作用)
【发布时间】:2016-04-21 08:56:48
【问题描述】:

我有很多这样的遗留测试。使用 unittest 跳过测试,但使用 nosetests 运行。

import unittest
import nose
import time


class BaseTestClass(unittest.TestCase):

    @unittest.skip("Skipped")
    def test_add(self):
        """Test 1"""
        print "Execute test 1"
        time.sleep(5)

    def test_sub(self):
        """Test 2"""
        print "Execute test 2"
        time.sleep(5)

if __name__ == '__main__':
    nose.run(argv=["nose", ".", "--verbosity=2", "--nocapture", '--no-skip'])

我想运行所有跳过的测试。 看起来像“no-skip” - 选项不起作用,变成我有输出

Execute test 2
Test 1 ... Test 2 ... ok

----------------------------------------------------------------------
Ran 2 tests in 5.001s

OK

看起来 test 存在于输出中,但不执行内部代码。

我希望看到:

Test 1 ... ok
Execute test 1
Test 2 ... ok
Execute test 2
----------------------------------------------------------------------
Ran 2 tests in 10 s

OK

【问题讨论】:

标签: python nose python-unittest


【解决方案1】:

我遇到了类似的问题,经过一些研究,问题似乎是 --no-skipunittests.skip 没有任何关系,但处理异常 nose.SkipTest

我最终得到了一个在我的情况下完成这项工作的 hacky 解决方案。也许它可以帮助某人。它包括使用您自己的自定义 skip 函数,以便它“搭载”--no-skip 标志并做出相应的反应。

import sys
import unittest

no_skip_mode = '--no-skip' in sys.argv

def skip(reason):
    if no_skip_mode:
        # Don't decorate the test function. Just return as is.
        def dummy_wrapper(fn):
            return fn

        return dummy_wrapper

    return unittest.skip(reason)

我猜你可以试试猴子补丁unittest.skip

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2019-08-08
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2015-03-21
    • 1970-01-01
    • 1970-01-01
    • 2011-07-21
    相关资源
    最近更新 更多