2

After reading How to get the function name as string in Python?

I wondered if it is somehow possible to put a logging statement into one of the

def setUp(self):
    ... 

def tearDown(self):
    ...

and print the name of the current test function.

Gobliins
  • 3,848
  • 16
  • 67
  • 122

1 Answers1

10

Testcases have a self.id() method that returns the current TestClassName.testMethodName.

The method uses self._testMethodName to build that string; you could use that attribute but the name of the attribute does flag it as internal. Relying on the attribute being there may not work in all Python versions.

Arthur
  • 525
  • 7
  • 18
Martijn Pieters
  • 1,048,767
  • 296
  • 4,058
  • 3,343