I am working on writing unit tests, but they needed to run as I added them to the TestSuite. So my problem is when I run the testrunner.py from the PyCharm I get what I need, but if I run the same file from the terminal the tests will be sorted alphabetically, and that is bad for me.
For example: I have 2 tests, test_dummy_01.py and test_dummy_01 in the "tests/" folder of my Framework. Also I created the testrunner.py file where I add the TestDummy02 class first and after the TestDummy01 class. So when I run the the testrunner.py from PyCharm the test_dummy_02.py test will run first and the test_dummy_01.py by second which is good for me. Now I need the same behavior when I run the same file in the terminal, but it will always run the test_dummy_01.py file first. So please if anyone can help me?
Folder hierarchy of my files:
Project/
tests/
test_dummy_01.py
test_dummy_02.py
testrunner.py
The test_dummy_01.py test: - the test_dummy_02.py file is same as this
class TestDummy01(BaseTestCase):
def setUp(self):
super(TestDummy, self).setUp()
def test_dummy_01(self):
driver = self.driver
login = LoginPage(driver)
login.enter_username("Something")
def tearDown(self):
super(TestDummy, self).tearDown()
The testrunner.py file where I added the order
import sys
import unittest
from tests.test_dummy_01 import TestDummy01
from tests.test_dummy_02 import TestDummy02
def suite():
suite_x = unittest.TestSuite()
suite_x.addTest(unittest.makeSuite(TestDummy02)) # In PyCharm this test is runned first, but in Teminal this will run by second
suite_x.addTest(unittest.makeSuite(TestDummy01))
return suite_x
def run():
result = unittest.TextTestRunner(verbosity=2).run(suite())
if not result.wasSuccessful():
sys.exit(1)
if __name__ == '__main__':
run()
PyCharm terminal