How to get currently running testcase name from testsuite in unittest

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.


unittest.TestCase._testMethodName

Example code:

import unittest


class BasicTests(unittest.TestCase):

    def test_print(self):
        print(self._testMethodName)