pythonassertunittest2

unavailiable assertion methods in python 3.1 unittest


I'm new to python programming and especially to unit-testing framework. For some reason working with pyDev (py 3.1 interpreter) I cannot use all of those new assert methods (such as assertRegexpMatches etc..).

Here's an example code:

class TestParser(unittest.TestCase):

    def testskipCommentAndSpaces(self):
        if os.path.isfile(sys.argv[1]):
            #self.vmFilesListPath = sys.argv[1]
            vmFilesListPath = sys.argv[1]
        else:
            #self.vmFilesListPath = get_all_vm_files(sys.argv[1])
            vmFilesListPath = get_all_vm_files(sys.argv[1])
        #parser = Parser(self.vmFilesListPath)
        parser = Parser(vmFilesListPath)
        commands = parser.getCommands()
        for command in commands:
            for token in commands:
                p=re.search(r"(////)",str(token)) 
                **self.assertNotRegexpMatches(str(token),p)**

What I get is: AttributeError: 'TestParser' object has no attribute 'assertNotRegexpMatches' Needless to say that: hasattr(self, 'assertNotRegexpMatches') returns false while the "simple" asserts methods works good.

I'm sure the interpreter is set to 3.1 - i.e the correct version I need (since I also have py 2.7 installed on my system).

Would thank you for your help, Igor.L


Solution

  • While the unittest module in Python 3.1 had an assertRegexpMatches method, there is no documented assertNotRegexpMatches. In Python 3.2, assertRegexpMatches was renamed to assertRegex and the complementary assertNotRegex was added.

    Note that Python 3.1 is obsolete and no longer maintained other than critical security fixes. There have been many features, fixes, and major performance improvements added in Python 3.2 and now 3.3 which was just released. Consider upgrading to one of them.