我想知道是否有可能将日志记录语句放入其中之一
def setUp(self):
...
def tearDown(self):
...
Run Code Online (Sandbox Code Playgroud)
并打印当前测试功能的名称。
我有很多功能,例如:
def DBworker_thatdoes_job7():
print "DBworker_thatdoes_job7 starting..."
... the actual code here ...
print "DBworker_thatdoes_job7 finished."
Run Code Online (Sandbox Code Playgroud)
如何在不硬编码函数名称的情况下执行此操作?这是我想要实现的目标:
def DBworker_thatdoes_job7():
print thisfunction.name + " starting..."
...
def DBworker_thatdoes_cleaning18():
print thisfunction.name + " starting..."
...
Run Code Online (Sandbox Code Playgroud)
注意:我已经看过如何在 Python 中将函数名作为字符串获取?但我真的没有看到在这里做这件事的好方法。此外,这个问题接近于在该函数内确定函数名称(不使用回溯),但这里适用于启动和结束时函数名日志记录的特定用例,因此不完全是重复的。
做一个类型的数学函数def.
def integral_error(integral,f):
------stufff-------
print integral
Run Code Online (Sandbox Code Playgroud)
给出类似的东西: '<function simpsons at 0xb7370a74>'
有没有办法让辛普森一家没有字符串操作?即只是功能名称?
有可能在python 2.7.3中获得这样一个定义的名称:
def Newname(self):
print name_of_def
> "Newname"
Run Code Online (Sandbox Code Playgroud)
谢谢,
PUX