[英]Get testing script filename and class name with nosetest
我跑了osetests --rednose --nocapture test_report.py
我得到了print(cls.__class__.__name__)
type
print(cls.__class__.__name__)
,但是我希望使用TestReport
和/usr/local/bin/nosetests
用於os.path.splitext(sys.modules['__main__'].__file__)[0]
,但是我期望test_report
如何獲得?
class TestReport(unittest.TestCase):
@classmethod
def setup_class(cls):
print(cls.__class__.__name__)
ap(os.path.splitext(sys.modules['__main__'].__file__))
TESTING_NAME=os.path.splitext(sys.modules['__main__'].__file__)[0]
print("testing script name:"+TESTING_NAME)
由於cls
參數肯定是一個class
,所以一個類的類型是type
,這就是您嘗試獲取它的__name__
時得到的。 只需嘗試cls.__name__
,看看是否能滿足您的期望。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.