Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to collect my tests with py.test?

Tags:

python

pytest

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()
like image 413
Jon Avatar asked Dec 14 '12 11:12

Jon


People also ask

How does py test work?

PyTest is a testing framework that allows users to write test codes using Python programming language. It helps you to write simple and scalable test cases for databases, APIs, or UI. PyTest is mainly used for writing tests for APIs. It helps to write tests from simple unit tests to complex functional tests.

What is test py?

pytest enables you to create marks, or custom labels, for any test you like. A test may have multiple labels, and you can use them for granular control over which tests to run. Later in this tutorial, you'll see an example of how pytest marks work and learn how to make use of them in a large test suite.

Where do I put pytest files?

While the pytest discovery mechanism can find tests anywhere, pytests must be placed into separate directories from the product code packages. These directories may either be under the project root or under the Python package.


1 Answers

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

like image 111
ecatmur Avatar answered Sep 21 '22 22:09

ecatmur