mercredi 29 août 2018

Running test suite from terminal using pytest executes python test scripts twice

i am trying to execute my following test suite:

import unittest
from Login_Page import LoginPageAndLogout


def test_suite():
    # get all tests from classes
    login_test = unittest.TestLoader().loadTestsFromTestCase(LoginPageAndLogout)

    # create a test suite
    all_tests = unittest.TestSuite([
        login_test
    ])

    # run the suite
    unittest.TextTestRunner(verbosity=2).run(all_tests)

from Pycharm's terminal using the command :

sudo pytest selenium-tests/testSuite.py -vvv -s

and a part of the output is the following:

============================================================================================================ test session starts ============================================================================================================
platform linux2 -- Python 2.7.14, pytest-3.1.3, py-1.4.34, pluggy-0.4.0 -- /usr/bin/python
cachedir: .cache
rootdir: /home/osboxes/PycharmProjects/WebTesting, inifile:
plugins: cov-2.5.1
collected 3 items 

selenium-tests/testSuite.py::LoginPageAndLogout::test_failed_login <- selenium-tests/Login_Page.py PASSED
selenium-tests/testSuite.py::LoginPageAndLogout::test_login <- selenium-tests/Login_Page.py FAILED
selenium-tests/testSuite.py::test_suite test_failed_login (Login_Page.LoginPageAndLogout) ... ok
test_login (Login_Page.LoginPageAndLogout) ... ok

----------------------------------------------------------------------
Ran 2 tests in 55.993s

The structure of my Login_Page.py file is:

class LoginPageAndLogout(unittest.TestCase):

    def setUp(self):
        # ...

    # login with incorrect credentials to get error message
    def test_failed_login(self):
        # ...

    # login with correct credentials
    def test_login(self):
        # ...

    def tearDown(self):
        # ...

As you can see from the output, I have 2 tests but the terminal collects three things instead and run each test twice. Is there a way to avoid this? I only want the PASSED/FAILED execution, not the ... ok Why does it do that? Note that I prefer to execute my tests using pytest.

Aucun commentaire:

Enregistrer un commentaire