在 setup() 中输出 pyunit 测试名称的方法
python 中有没有一种方法可以让 pyunit 测试输出当前正在运行的测试。例子:
def setUp(self):
log.debug("Test %s Started" % (testname))
def test_example(self):
#do stuff
def test_example2(self):
#do other stuff
def tearDown(self):
log.debug("Test %s Finished" % (testname))
Is there a way in python for a pyunit test to output the test it's currently running. Example:
def setUp(self):
log.debug("Test %s Started" % (testname))
def test_example(self):
#do stuff
def test_example2(self):
#do other stuff
def tearDown(self):
log.debug("Test %s Finished" % (testname))
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
您可以使用
self._testMethodName
。这是继承自unittest.TestCase
父类。
You can use
self._testMethodName
. This is inherited from theunittest.TestCase
parent class.您可以在以下位置找到文档:
http://docs.python.org/library/unittest.html# unittest.TestCase.id
编辑:
对于 2.7 用户,
https://docs.python.org/2.7/library/ unittest.html#unittest.TestCase.id
You can find the Documentation at:
http://docs.python.org/library/unittest.html#unittest.TestCase.id
edit:
For 2.7 users,
https://docs.python.org/2.7/library/unittest.html#unittest.TestCase.id
您可以使用
str(self.id()).split()[4]
。可以在这里找到 http://docs.python.org/library/ unittest.html#unittest.TestCase.idYou can use
str(self.id()).split()[4]
. It could be found here http://docs.python.org/library/unittest.html#unittest.TestCase.id