[英]Get testing script filename and class name with nosetest
I ran the osetests --rednose --nocapture test_report.py
我跑了osetests --rednose --nocapture test_report.py
I got type
for print(cls.__class__.__name__)
, but I expected TestReport
我得到了print(cls.__class__.__name__)
type
print(cls.__class__.__name__)
,但是我希望使用TestReport
and /usr/local/bin/nosetests
for os.path.splitext(sys.modules['__main__'].__file__)[0]
, but I expected test_report
和/usr/local/bin/nosetests
用于os.path.splitext(sys.modules['__main__'].__file__)[0]
,但是我期望test_report
How to get it ? 如何获得?
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)
Since the cls
parameter is most certainly a class
, the class of a class is of the type type
, and that's what you got when you tried to get the __name__
of it. 由于cls
参数肯定是一个class
,所以一个类的类型是type
,这就是您尝试获取它的__name__
时得到的。 Just try cls.__name__
and see if that gives you what you expect. 只需尝试cls.__name__
,看看是否能满足您的期望。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.