0

So my question is pretty general. I am starting to learn how to use tests in Python. Based off my research I found a couple great blogs that walk through testing in Python. One of them is Test-Driven Development by Jason Diamond. Long story short I copied the code he recommended into Python. Here's the code:

class DatePattern:

    def __init__(self, year, month, day):
        pass

    def matches(self, date):
        return True

class DatePattern(unittest.TestCase):

    def testMatches(self):
        p=DatePattern(2015,5,14)
        d=datetime.date(2015,5,14)
        self.failUnless(p.matches(d))

def main():
    unittest.main()

if __name__ == '__main__':
    main()

According to him this test is supposed to pass. However when I run it, a type error shows up explaining that __init__ only takes one to two positional arguments and you have four. And it does not pass? Can someone help explain what the issue is? And along the way explain the best technique to finding bugs when issues arise with the constructor?

2
  • 2
    Rename your test class so there are no name conflicts... Commented May 14, 2015 at 18:19
  • If you think that this setup is awkward, and you get tired of creating classes for tests, extending TestCase, I have found pytest to be much easier to use. Commented May 14, 2015 at 18:58

1 Answer 1

1

You define a class named "DatePattern", and then you define a second class named "DatePattern". The second overwrites the first. Give them different names.

Sign up to request clarification or add additional context in comments.

Comments

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.