0

How can I add simple test method from unittest.TestCase to TestSuite. As I see it is only possible to add whole class only to suite, for example I want something like this:

import unittest


class MyBaseTestCase(unittest.TestCase):
    @classmethod
    def setUpClass(cls):
        cls.abs = "test"


class MyTestClass(MyBaseTestCase):
    def test_abs(self):
        if self.abs:
            pass


class MyTestSuite(unittest.TestSuite):
    def __init__(self):
        super().__init__()
        self.addTest(MyTestClass.test_abs)

Here I get an error: AttributeError: 'TeamcityTestResult' object has no attribute 'abs'. It seems like it runs as a test, but setUpClass does not calls.

Ivan Bryzzhin
  • 2,009
  • 21
  • 27

1 Answers1

1

How did you run the test suite? I used your code and ran it using 'python3 -m unittest test.py':

import unittest


class MyBaseTestCase(unittest.TestCase):
    @classmethod
    def setUpClass(cls):
        cls.abs = "test"


class MyTestClass(MyBaseTestCase):
    def test_abs(self):
        if self.abs:
            pass


class MyTestSuite(unittest.TestSuite):
    def __init__(self):
        super().__init__()
        self.addTest(MyTestClass.test_abs)

And it works.

Stanowczo
  • 753
  • 5
  • 21
  • Thank you for point. I use IntelljIdea for run it. And configure run it as module and choose test.MyTestSuite there, which makes command like this: `python.exe C:\Users\Me\.IntelliJIdea2018.3\config\plugins\python\helpers\pycharm\_jb_unittest_runner.py --target test.MyTestSuite` that call python with `python -m unittest test.MyTestSuite`. If I choose whole file with testSuite with command `python -m unittest test.py` it starts work. – Ivan Bryzzhin Oct 09 '18 at 14:21