-
Notifications
You must be signed in to change notification settings - Fork 1.3k
Description
I asked an LLM to give me an example Python unit test suite. I got this:
# calculator.py
def add(x, y):
return x + y
def subtract(x, y):
return x - y
def multiply(x, y):
return x * y
def divide(x, y):
if y == 0:
raise ValueError("Cannot divide by zero")
return x / y
# test_calculator.py
import unittest
from calculator import add, subtract, multiply, divide
class TestCalculator(unittest.TestCase):
def test_add(self):
self.assertEqual(add(1, 2), 3)
self.assertEqual(add(-1, 1), 0)
self.assertEqual(add(-1, -1), -2)
def test_subtract(self):
self.assertEqual(subtract(10, 5), 5)
self.assertEqual(subtract(-1, 1), -2)
self.assertEqual(subtract(-1, -1), 0)
def test_multiply(self):
self.assertEqual(multiply(4, 5), 20)
self.assertEqual(multiply(-1, 1), -1)
self.assertEqual(multiply(-1, -1), 1)
def test_divide(self):
self.assertEqual(divide(8, 4), 2)
self.assertEqual(divide(-1, 1), -1)
self.assertEqual(divide(-1, -1), 1)
with self.assertRaises(ValueError):
divide(1, 0)
if __name__ == '__main__':
unittest.main()
I created these two files. I installed the Python extension. The Testing view appeared. But now the troubles start:
π The editor is unable to detect that I use unittest, so it asks me to configure stuff. The configuration is weird since it asks me for the root of the tests and for the right test glob to use (why aren't we just picking good defaults here, instead of forcing the user to make a decision?):
π After configuring the tests I am immediately greeted with an error. The error is also weirdly shown as a list row (cc @connor4312).
π After reloading I can now run the tests. I then run Run Tests with Coverage and immediately the next error comes up. Should the extension automatically take care of installing this for me?
