在python 2.7中,我使用unittest模块并编写测试,而其中一些被@ unittest.skip跳过。 我的代码如下:
import unittest
class MyTest(unittest.TestCase):
def test_1(self):
...
@unittest.skip
def test_2(self):
...
我的文件夹中有很多这样的测试文件,并且我使用测试发现来运行所有这些测试文件:
/%python_path/python -m unittest discover -s /%my_ut_folder% -p "*_unit_test.py"
这样,该文件夹中的所有* _unit_test.py文件都将运行。在以上代码中,将同时运行test_1和test_2。我想要的是所有带有@ unittest.skip的测试用例,例如我上面的代码中的test_2应该被跳过。我该如何实现?
任何帮助或建议将不胜感激!
答案 0 :(得分:1)
尝试将字符串参数添加到@ unittest.skip装饰器,如下所示:
function ClearOutput(){
console.log("Cleared Output");
document.querySelector("iron-icon[command = 'clear-focused-or-selected-outputs']").click()
}
setInterval(ClearOutput,60000)
在python 2.7中不带字符串参数运行可以给我以下内容:
import unittest
class TestThings(unittest.TestCase):
def test_1(self):
self.assertEqual(1,1)
@unittest.skip('skipping...')
def test_2(self):
self.assertEqual(2,4)
而在python 2.7中运行文本会给我:
.E
======================================================================
ERROR: test_2 (test_test.TestThings)
----------------------------------------------------------------------
Traceback (most recent call last):
File "/usr/lib64/python2.7/functools.py", line 33, in update_wrapper
setattr(wrapper, attr, getattr(wrapped, attr))
AttributeError: 'TestThings' object has no attribute '__name__'
----------------------------------------------------------------------
Ran 2 tests in 0.001s
有关更多详细信息,请参见https://docs.python.org/3/library/unittest.html或https://www.tutorialspoint.com/unittest_framework/unittest_framework_skip_test.htm