简体   繁体   中英

How to collect my tests with py.test?

I try to collect my tests with py.test but it doesn't do so.

  • Do I have to provide additional options at the command line?

  • Py.test was executed in the directory of my .py-file. Are there any other requirements?

  • Are my tests named correctly? In my code I used 'Test-' for classes and 'test_' for methods.

The results from the terminal:

> 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 

My code under test:

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()

In the default configuration, the test file should be named test_<something>.py . See Changing standard (Python) test discovery .

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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