Hello,
I am doing the project for the unit testing part of intermediate python, I stumbled upon a problem that when reviewing the solutions I couldn’t understand why the line was added to somehow solve the problem.
When I run the code, it gives me an error message of the skipped test. I am assuming that the added line re-creates a new incident of the testing ‘environment’ I.e. the class; without it somehow iterating over and over caused the code to not skip the test which followed?
# Write your code below:
import unittest
import surfshop
class SurfShopCartTests(unittest.TestCase):
def setUp(self):
self.cart = surfshop.ShoppingCart()
# tests:
def test_add_surfboards(self):
testing_parameters = [2,3,4]
for board in testing_parameters:
with self.subTest(board):
result = self.cart.add_surfboards(board)
expected = 'Successfully added {} surfboards to cart!'.format(board)
self.assertEqual(result, expected)
# self.cart = surfshop.ShoppingCart(). **** THIS IS THE LINE, IF I UNCOMMENT IT WORKS ****
@unittest.skipIf(surfshop.off_season, "It's the off season")
def test_error_add_surfboards(self):
self.assertRaises(surfshop.TooManyBoardsError, self.cart.add_surfboards, quantity=5)
@unittest.expectedFailure
def test_applying_local_discounts(self):
self.cart.apply_locals_discount()
self.assertTrue(self.cart.locals_discount)
unittest.main()
Thank you so much, I am sorry I couldn’t explain it better <3