在 setup() 中输出 pyunit 测试名称的方法

发布于 2024-10-08 09:40:36 字数 292 浏览 0 评论 0原文

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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

甜点 2024-10-15 09:40:36

您可以使用self._testMethodName。这是继承自unittest.TestCase父类。

def setUp():
    print("In method", self._testMethodName)

You can use self._testMethodName. This is inherited from the unittest.TestCase parent class.

def setUp():
    print("In method", self._testMethodName)
橙味迷妹 2024-10-15 09:40:36

您可以使用str(self.id()).split()[4]。可以在这里找到 http://docs.python.org/library/ unittest.html#unittest.TestCase.id

You can usestr(self.id()).split()[4]. It could be found here http://docs.python.org/library/unittest.html#unittest.TestCase.id

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文