How to get currently running testcase name from testsuite in unittest

后端 未结 2 1410
一向
一向 2020-12-09 09:02

How can I get currently running testcase name, while in the testsuite collection there are 16 testcases. Tests are executed sequentially (in the order of ad

相关标签:
2条回答
  • 2020-12-09 09:37

    unittest.TestCase._testMethodName

    Example code:

    import unittest
    
    
    class BasicTests(unittest.TestCase):
    
        def test_print(self):
            print(self._testMethodName)
    
    0 讨论(0)
  • 2020-12-09 09:50

    unittest.TestCase.shortDescription()

    Returns a description of the test, or None if no description has been provided. The default implementation of this method returns the first line of the test method’s docstring, if available, or None.

    unittest.TestCase.id()

    Return a string identifying the specific test case. This is usually the full name of the test method, including the module and class name.

    Hopefully one of those is useful for your needs.

    0 讨论(0)
提交回复
热议问题