簡體   English   中英

如何使用py.test收集我的測試?

[英]How to collect my tests with py.test?

我嘗試用py.test收集我的測試,但它沒有這樣做。

  • 我是否必須在命令行中提供其他選項?

  • Py.test在我的.py文件目錄中執行。 還有其他要求嗎?

  • 我的測試名稱是否正確? 在我的代碼中,我使用'Test-'表示類,'test_'表示方法。

終端的結果:

> py.test

===============================  in 0.00 seconds ============================
user@host:~/workspace/my_project/src/html_extractor$ py.test

============================= test session starts ===========================
platform linux2 -- Python 2.7.3 -- pytest-2.3.4
plugins: xdist
collected 0 items 

我的測試代碼:

class Factories(object):
    TEST_LINKS = ['http://www.burgtheater.at',
                  'http://www.musikverein.at/']

    def links(self):
        for link in self.TEST_LINKS:
            yield link


class TestHTMLExtractor(unittest.TestCase):

    def setUp(self):
        self.factory = Factories()
        self.extractor = HTMLExtractor()


    def test_extract_site_return(self):
        for link in self.factory.links():
             raw_html_page = self.extractor.run(link)

def test_whatever():
    pass

if __name__ == '__main__':
    unittest.main()

在默認配置中,測試文件應命名為test_<something>.py 請參閱更改標准(Python)測試發現

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM