获取Nose找到的所有测试的数据结构
Get data structure of all tests found by Nose
我如何获得某种包含 Nose 发现的所有测试列表的数据结构?我遇到了这个:
List all Tests Found by Nosetest
我正在寻找一种在我自己的 python 脚本中获取单元测试名称列表的方法(以及位置或虚线位置)。
有几种方法可以实现:一种是 运行 nose with xunit plugin with --collect-only
并解析生成的 junit xml 文件。或者,您可以添加一个捕获测试名称的基本插件,如下所示:
import sys
from unittest import TestCase
import nose
from nose.tools import set_trace
class CollectPlugin(object):
enabled = True
name = "test-collector"
score = 100
def options(self, parser, env):
pass
def configure(self, options, conf):
self.tests = []
def startTest(self, test):
self.tests.append(test)
class MyTestCase(TestCase):
def test_long_integration(self):
pass
def test_end_to_end_something(self):
pass
if __name__ == '__main__':
# this code will run just this file, change module_name to something
# else to make it work for folder structure, etc
module_name = sys.modules[__name__].__file__
plugin = CollectPlugin()
result = nose.run(argv=[sys.argv[0],
module_name,
'--collect-only',
],
addplugins=[plugin],)
for test in plugin.tests:
print test.id()
你的测试信息全部抓取到plugin.test
结构中。
我如何获得某种包含 Nose 发现的所有测试列表的数据结构?我遇到了这个:
List all Tests Found by Nosetest
我正在寻找一种在我自己的 python 脚本中获取单元测试名称列表的方法(以及位置或虚线位置)。
有几种方法可以实现:一种是 运行 nose with xunit plugin with --collect-only
并解析生成的 junit xml 文件。或者,您可以添加一个捕获测试名称的基本插件,如下所示:
import sys
from unittest import TestCase
import nose
from nose.tools import set_trace
class CollectPlugin(object):
enabled = True
name = "test-collector"
score = 100
def options(self, parser, env):
pass
def configure(self, options, conf):
self.tests = []
def startTest(self, test):
self.tests.append(test)
class MyTestCase(TestCase):
def test_long_integration(self):
pass
def test_end_to_end_something(self):
pass
if __name__ == '__main__':
# this code will run just this file, change module_name to something
# else to make it work for folder structure, etc
module_name = sys.modules[__name__].__file__
plugin = CollectPlugin()
result = nose.run(argv=[sys.argv[0],
module_name,
'--collect-only',
],
addplugins=[plugin],)
for test in plugin.tests:
print test.id()
你的测试信息全部抓取到plugin.test
结构中。