繁体   English   中英

使用鼻子测试获取测试脚本文件名和类名

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

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM