I have the following project structure:
/root
/tests
common_test_case.py
test_case_1.py
test_case_2.py
...
project_file.py
...
Every test test_case_...
is inherited from both unittest.TestCase
and common_test_case.CommonTestCase
. Class CommonTestCase
contains test methods that should be executed by all the tests (though using data unique to each test, stored and accessed in self.something
of the test). If some specific tests are needed for an exact test case, they are added directly to that particular class.
Currently I am working on adding logging to my tests. Among other things I would like to log the class the method was run from (since the approach above implies the same test method name for different classes). I would like to stick with the built-in logging module to achieve this.
I have tried the following LogRecord attributes:%(filename)s
, %(module)s
, %(pathname)s
. Though, for methods defined in common_test_case.py
they all return path/name to the common_test_case.py
and not the test module they were actually run from.
My questions are:
- Is there a way to achieve what I am trying to, using only built-in
logging
module? - Using some third-party/other module (I was thinking maybe some "hacky" solution with
inspect
)? - Is it possible to achieve (in Python) at all?