簡體   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