Traceback (most recent call last):
File âtests.pyâ, line 15, in test_add_surfboards
self.assertRaises(surfshop.TooManyBoardsError, self.cart.add_surfboards(3))
File â/usr/lib/python3.6/unittest/case.pyâ, line 733, in assertRaises
return context.handle(âassertRaisesâ, args, kwargs)
File â/usr/lib/python3.6/unittest/case.pyâ, line 178, in handle
callable_obj(*args, **kwargs)
TypeError: âstrâ object is not callable
the raise of the Exception âTooManyBoardsErrorâ pops because the setUp function runs only once when you call the subTest. What I did is to create an new instance for each of the subTest:
def test_add_more_surfboards(self):
num_surfboards = [2, 3, 4]
for num in num_surfboards:
self.cart = surfshop.ShoppingCart()
with self.subTest(num):
self.assertEqual(self.cart.add_surfboards(num), f'Successfully added {num} surfboards to cart!', "Check adding surfboards to a cart")
if not, you will cumulate the surfboards in the instance created at the beginning of the tests.
The solutions does not even include step 6!!! Can we have some guidance or explanation for the solutions??? A video explanation would be really appreciated! Or at least a step by step explanation!
Hey, thank you for confirming my expectations. I was trying to figure what was happening that I was getting an error on this checkpoint, and I had arrived to the same conclusion.