[英]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.