0

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 execute only the PASSED/FAILED execution, not the ... ok ?

If I comment out unittest.TextTestRunner(verbosity=2).run(all_tests) my tests executed only once but I get the ... ok result instead of the PASSED/FAILED which is the one I want; so I see the pytest execution results instead of the unittests runner results.

How can I run from the terminal my suite using the unitest runner only?

0

The solution to this was quite easy as I had just misunderstood how my unit test was being executed all this time.

The only thing I had to do was to comment out the whole test_suite class from my testSuite.py file and just import at the top of this file the classes from the test scripts i wanted to execute.

Now my tests run only once and I can still execute all my scripts all at once without typing them in my command one by one using the exact same command: sudo pytest selenium-tests/testSuite.py -vvv -s

The output of that command is now:

osboxes@osboxes:~/PycharmProjects/WebTesting$ sudo pytest selenium-tests/testSuite.py -vvv -s
========================================================================================================================= 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 2 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 PASSED

====================================================================================================================== 2 passed in 58.81 seconds =======================================================================================================================
osboxes@osboxes:~/PycharmProjects/WebTesting$ 

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.