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

Testing - Test View for Python unittest #17039

Closed
3 tasks done
karthiknadig opened this issue Aug 19, 2021 · 7 comments
Closed
3 tasks done

Testing - Test View for Python unittest #17039

karthiknadig opened this issue Aug 19, 2021 · 7 comments

Comments

@karthiknadig
Copy link
Member

karthiknadig commented Aug 19, 2021

Refs: #15750

Complexity: 3

Create Issue


Requirements

  1. Install python extension from here: https://pvsc.blob.core.windows.net/extension-builds/ms-python-insiders.vsix
  2. Make sure you have "python.experiments.optInto": ["All"], in your user settings. If you did not have it, add it and reload.

Testing

  1. Open an empty folder in VS Code.
  2. Add following unittest code (name your file my_tests.py). Do not name it unittest.py that will override the unittest library:
import unittest
class PassingTests(unittest.TestCase):
    def test_passing(self):
        self.assertEqual(42, 42)
    def test_passing_still(self):
        self.assertEqual("silly walk", "silly walk")
class FailingTests(unittest.TestCase):
    def test_failure(self):
        self.assertEqual(42, -13)
    def test_failure_still(self):
        self.assertEqual("I'm right!", "no, I am!")
  1. Select any python version.
  2. You can either configure tests using Python: configure tests... command from the command pallet, or go the test view and configure by using the welcome view, or you can run tests to get a prompt to configure.
  3. Select unittest framework.
  4. You should see the tests in the test view. Run the tests.
  5. Add your own test methods, or add another test file, the test UI should update accordingly.
@karthiknadig karthiknadig added this to the August 2021 milestone Aug 19, 2021
@github-actions github-actions bot added triage-needed Needs assignment to the proper sub-team invalid-testplan-item and removed testplan-item labels Aug 19, 2021
@karthiknadig karthiknadig added testplan-item and removed triage-needed Needs assignment to the proper sub-team invalid-testplan-item labels Aug 19, 2021
@alexr00
Copy link
Member

alexr00 commented Aug 24, 2021

I followed both of the Requirements steps, but I wasn't able to get this working. Am I missing something?

recording (67)

@gregvanl
Copy link

gregvanl commented Aug 24, 2021

@alexr00 It looks like the test file detection is really fragile. For example if you specify searching for the pattern "*test.py", it will detect a file called "utest.py" but not with more than one character (for example "untest.py").
I was able to get detection to work most reliably with just "test.py".
I'll enter an issue.

@alexr00
Copy link
Member

alexr00 commented Aug 24, 2021

Tried your suggestion @gregvanl of naming the file utest.py, but it still doesn't work.

@karthiknadig
Copy link
Member Author

I see that the file name is unittest.py, in python the file names are module names. So, if you create a file by the name unittest.py then import unittest in it then it overrides the underlying unittest library. Please name it something else.

@karthiknadig
Copy link
Member Author

@alexr00 When the config settings are generated see if they look like this. If not, try and add this to settings.json for the project and see if that helps:

{
    "python.testing.unittestArgs": [
        "-v",
        "-s",
        ".",
        "-p",
        "*test*.py"
    ],
    "python.testing.pytestEnabled": false,
    "python.testing.unittestEnabled": true
}

@DonJayamanne
Copy link

Verified

@DonJayamanne DonJayamanne removed their assignment Aug 24, 2021
@gregvanl gregvanl removed their assignment Aug 24, 2021
@alexr00
Copy link
Member

alexr00 commented Aug 25, 2021

I had tested with utest.py yesterday without success. Today I deleted everything in my folder, reloaded, and started over. Success.

@alexr00 alexr00 removed their assignment Aug 25, 2021
@alexr00 alexr00 closed this as completed Aug 25, 2021
@github-actions github-actions bot locked as resolved and limited conversation to collaborators Sep 25, 2021
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

4 participants