2

I know it is a bit silly question, but using links provides below, I am still unable to create testsuite.

I have now two test cases (there will be much more), let assume that the name of there are:

class step1(unittest.TestCase):

    def setUp(self):
        self.driver = webdriver.Firefox()

    def test_case1(self):
[...]

if __name__ == "__main__":
     unittest.main()

and:

class step2(unittest.TestCase):

    def setUp(self):
        self.driver = webdriver.Firefox()

    def test_case2(self):
[...]

if __name__ == "__main__":
     unittest.main()

I want to create other file .py file: testsuite, which can aggregate test_case1, test_case2, test_case3...

I tried something like that, for example:

import unittest
import step1
import step2


def suite():
    test_suite = unittest.TestSuite()
    test_suite.addTest(unittest.step1(test_case1))
    test_suite.addTest(unittest.step2(test_case2))

if __name__ == "__main__":
    result = unittest.TextTestRunner(verbosity=2).run(suite())
    sys.exit(not result.wasSuccessful())

Error: AttributeError: 'module' object has no attribute 'step1'

1 Answer 1

3

You can use addTest() and pass TestCase instance to it, you also miss return statement:

def suite():
    test_suite = unittest.TestSuite()
    test_suite.addTest(step1())
    test_suite.addTest(step2())
    return test_suite

or, in one line using addTests():

test_suite.addTests([step1(), step2()])
Sign up to request clarification or add additional context in comments.

3 Comments

Probalby it is better, but still getting: AttributeError: 'module' object has no attribute 'addTest'
@ti01878 oops, sure, fixed the mistake. Thanks. Note that the code assumes step1, step2 are test cases.
Well, my code was so bad that I have to do 2 things more: 1) stackoverflow.com/questions/19087189/… and 2) stackoverflow.com/questions/18928826/…, but finnaly it works :) Thank you.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.