0

So I'm writing unit test cases in python for the first time. Here's what I've got so far

 import unittest
 from . BinarySearchTree import BinarySearchTree

 def Test_bst(unittest.TestCase):

    def setUp(self):
        bst = BinrySearchTree()
        bst.put(21, "a")
        bst.put(18, "b")
        bst.put(10, "c")
        bst.put(40, "d")
        bst.put(8, "e")
        bst.put(11, "f")

    def test_get(self):
        self.assertEqual("f", bst.get(11))

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

main()

Obviously I'm testing a binary search tree in the same directory. The issue I'm having is when I run this file I get an error that looks like

  File "Test_bst.py", line 4
    def Test_bst(unittest.TestCase):
                         ^
SyntaxError: invalid syntax

I'm just pretty confused because I've been reading all of the documentation and I'm pretty sure it's all correct and I can't find any similar issues. Thanks y'all

2
  • 1
    A function cannot inherit anything. Perhaps that was supposed to be a class, not a def? Commented Oct 28, 2020 at 23:59
  • have a look at my unittest demo github.com/IT-Support-L2/Unit_Test_Demo/tree/master/… Commented Oct 29, 2020 at 0:09

1 Answer 1

1

I think you mean:

class Test_bst(unittest.TestCase):

instead of

def Test_bst(unittest.TestCase):

I'd recommend reading the unittest documentation on how to use the library, which also includes a basic example for creating test cases by inheriting from unittest.TestCase.

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

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.