【问题标题】:How to extract the test method name from a test method in python如何从python中的测试方法中提取测试方法名称
【发布时间】:2012-11-10 20:09:59
【问题描述】:

我有各种 python unitttest 方法打包为一个 TestSuite,一个特定的测试方法看起来像例如

<input.MyTest testMethod=test_simple>

看起来这是一个类(这个东西的类型是input.MyTest)但是有一个额外的属性(?)testMethod。

如何从属性testMethod(或其他任何东西)中提取名称test_simple

测试代码(MyTest.py)

class MyTest(unittest.TestCase):
   def test_simple(self):
       pass

套件代码

from input import MyTest
suite = test.TestSuite()
suite.addTest(MyTest("test_simple"))
print suite._tests[0]

【问题讨论】:

  • 显示你的代码,不显示它,你让这个问题更不容易回答。
  • 我也想知道 MyTest 和 MyClass 的东西。请详细说明!

标签: python unit-testing test-suite


【解决方案1】:

通过快速阅读文档,您可能希望从test.id()开始

id()

返回一个标识特定测试用例的字符串。 这通常是测试方法的全名,包括模块和 类名。

【讨论】:

  • @Alex 下次先看看文档,你可能会解决自己的问题。
猜你喜欢
  • 1970-01-01
  • 2021-02-17
  • 1970-01-01
  • 1970-01-01
  • 2012-03-28
  • 2016-08-15
  • 2012-09-24
  • 2011-02-26
  • 1970-01-01
相关资源
最近更新 更多