AttributeError: object has no attribute 'runTest'
Question: I'm am new to `unittest` and I am not sure why I am getting this error:

    
    
    runTest (__main__.TestTimeInterval)
    No test ... Traceback (most recent call last):
      File "/Users/bli1/Development/Trinity/qa-trinity/python_lib/qe/tests/test_timestamp_interval.py", line 122, in <module>
        sys.exit(main(sys.argv))
      File "/Users/bli1/Development/Trinity/qa-trinity/python_lib/qe/tests/test_timestamp_interval.py", line 110, in main
        result_set = runner.run(suite)
      File "/Library/Frameworks/Python.framework/Versions/3.4/lib/python3.4/unittest/runner.py", line 168, in run
        test(result)
      File "/Library/Frameworks/Python.framework/Versions/3.4/lib/python3.4/unittest/suite.py", line 87, in __call__
        return self.run(*args, **kwds)
      File "/Library/Frameworks/Python.framework/Versions/3.4/lib/python3.4/unittest/suite.py", line 125, in run
        test(result)
      File "/Library/Frameworks/Python.framework/Versions/3.4/lib/python3.4/unittest/case.py", line 625, in __call__
        return self.run(*args, **kwds)
      File "/Library/Frameworks/Python.framework/Versions/3.4/lib/python3.4/unittest/case.py", line 555, in run
        testMethod = getattr(self, self._testMethodName)
    AttributeError: 'TestTimeInterval' object has no attribute 'runTest'
    

I wanted to create a simple test to see if everything is working properly but
I got the error above. I added the test to the suite and then ran it with
`.run()`

    
    
    class TestTimeInterval(unittest.TestCase):
        def __init__(self, log, runtag, interval, path_file):
            super(TestTimeInterval, self).__init__()
            self.interval = interval
            self.path_file = path_file
            self.log = log
            self.runtag = runtag
    
        def test_record(self):
            self.assertTrue(1 > 0)
    
    
    ##############################################################################
    def main(argv):
        exit_code = 0
        global me; me = os.path.basename(argv[0]) # name of this program
        global mydir; mydir = os.path.dirname(os.path.abspath(__file__))
        parser = argparse.ArgumentParser(description=main.__doc__)
        parser.add_argument("file", metavar="FILE",
                            help="File filled with hdfs paths separated by newlines")
        parser.add_argument("runtag", metavar="RUNTAG", help="tag for the test run")
        parser.add_argument("-t", "--time", default="10", dest="interval",
                            help="Time interval (minutes) between server_timestamp and interval given by HDFS folder name")
        args = parser.parse_args(args=argv[1:])
        log = logging.getLogger(me)
        logfile = args.runtag + ".log"
        if os.path.exists(logfile):
            os.remove(logfile)
        log.addHandler(logging.FileHandler(logfile))
        console = logging.StreamHandler(sys.stderr); console.setLevel(logging.WARNING); log.addHandler(console)
        if exit_code == 0:
            runner = unittest.TextTestRunner(stream=sys.stdout, descriptions=True, verbosity=2)
            suite = unittest.TestSuite()
            print(args)
            suite.addTest(TestTimeInterval(log, args.runtag, args.interval, args.file))
            try:
                log.info("{0}: START: {1}".format(me, datetime.datetime.now().ctime()))
                result_set = runner.run(suite)
            except KeyboardInterrupt as e:
                log.info("{0}: exit on keyboard interrupt".format(me))
                exit_code = 1
            else:
                exit_code = len(result_set.errors) + len(result_set.failures)
            finally:
                log.info("{0}: FINISH: {1}".format(me, datetime.datetime.now().ctime()))
        return exit_code
    ##############################################################################
    # The following code calls main only if this program is invoked standalone
    if __name__ == "__main__":
        sys.exit(main(sys.argv))
    


Answer: You almost never need to create TestSuites and TestRunners yourself. Normally,
you'd do something like:

    
    
    # my_test.py
    import unittest
    
    class Something(object):
        def __init__(self):
            self.foo = 1
    
    class TestSomething(unittest.TestCase):
        def setUp(self):
            super(TestSomething, self).setUp()
            self.something = Something()
    
        def test_record(self):
            self.assertTrue(1 > 0)
    
        def test_something_foo_equals_1(self):
            self.assertEqual(self.something.foo, 1)
    
    
    if __name__ == '__main__':
        unittest.main()
    

now, to run your test, you just execute your script.

    
    
    python my_test.py
    

