Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Improve first-time testing (& coverage) experience #24766

Open
joaomoreno opened this issue Jan 31, 2025 · 3 comments
Open

Improve first-time testing (& coverage) experience #24766

joaomoreno opened this issue Jan 31, 2025 · 3 comments
Assignees
Labels
area-testing bug Issue identified by VS Code Team member as probable bug info-needed Issue requires more information from poster triage-needed Needs assignment to the proper sub-team

Comments

@joaomoreno
Copy link
Member

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?):

Image Image

🐛 After configuring the tests I am immediately greeted with an error. The error is also weirdly shown as a list row (cc @connor4312).

Image

🐛 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?

Image
@joaomoreno joaomoreno added the bug Issue identified by VS Code Team member as probable bug label Jan 31, 2025
@github-actions github-actions bot added the triage-needed Needs assignment to the proper sub-team label Jan 31, 2025
@joaomoreno
Copy link
Member Author

Actually pip install coverage didn't solve the last error for me. I don't even know how to proceed.

@connor4312
Copy link
Member

connor4312 commented Jan 31, 2025

The error is also weirdly shown as a list row

This is intentional so that test providers can show 'per-item' information, e.g. if an AST-parsing test extension is unable to parse a single file out of the workspace, it can show that.

@karthiknadig
Copy link
Member

We are working on improving this flow. But, before we do the test part, we actually need to "fix" install flow. See in python when you run pip install <package> you might be installing the wrong thing in the wrong place. Wrong thing, because install names in python can be different from package names. Wrong place because (here is Brett's detailed explanation https://snarky.ca/why-you-should-use-python-m-pip/). We need installation in many areas, like notebook, terminal quick fix, make it easy for copilot to install things if needed, also need to handle install permissions. @eleanorjboyd will be looking into this part of it.

You are right about making it easier to do test config. We are going towards a no-config solution for everything python. We just shipped no-config debugging for python (since the area covered by that is the largest) and works with/without AI. we plan on doing no-config for testing as well. What we have now is the legacy support for this, and I agree that it is cumbersome. Eleanors work will feed into the no-config solution, also into many other places, eliminating the wrong thing in the wrong place problem.

@github-actions github-actions bot added the info-needed Issue requires more information from poster label Jan 31, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area-testing bug Issue identified by VS Code Team member as probable bug info-needed Issue requires more information from poster triage-needed Needs assignment to the proper sub-team
Projects
None yet
Development

No branches or pull requests

4 participants