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,553
  • 14
  • 63
  • 109

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
  • 417
  • 6
  • 15
Martijn Pieters
  • 963,270
  • 265
  • 3,804
  • 3,187