[英]Run skipped tests by nosetest (no-skip doesn't work)
I have a lot of legacy test like this. 我有很多这样的遗留测试。 Tests are skipped with unittest but are run with 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'])
I want to run all skipped tests. 我想运行所有跳过的测试。 Looks like "no-skip" - option not works, become I have output 看起来像“不跳过”-选项不起作用,成为我的输出
Execute test 2
Test 1 ... Test 2 ... ok
----------------------------------------------------------------------
Ran 2 tests in 5.001s
OK
looks like test is present in output but doesn't execute code inside. 看起来测试出现在输出中,但不执行内部代码。
I expected to see: 我希望看到:
Test 1 ... ok
Execute test 1
Test 2 ... ok
Execute test 2
----------------------------------------------------------------------
Ran 2 tests in 10 s
OK
I got a similar problem, and after some research the issue seems to be that --no-skip
does not have anything to do with unittests.skip
but with the handling the exception nose.SkipTest
. 我遇到了类似的问题,经过一番研究,问题似乎是--no-skip
与unittests.skip
没有任何关系,但与处理exception.SkipTest nose.SkipTest
。
I ended up with a hacky solution that does the job in my case. 我最终得到了一个骇人听闻的解决方案,可以解决我的问题。 Maybe it can help somebody. 也许它可以帮助别人。 It consists of using your own custom skip
function so that it "piggybacks" the --no-skip
flag and reacts accordingly. 它包含使用您自己的自定义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)
I guess you could try to monkeypatch unittest.skip
. 我猜你可以尝试monkeypatch unittest.skip
。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.