Skip to content

Testing - Test View for Python unittest #17039

Closed

Description

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.

Activity

  1. alexr00 commented on Aug 24, 2021

    @alexr00
    Member

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

    recording (67)

  2. gregvanl commented on Aug 24, 2021

    @gregvanl

    Alex Ross (@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.

  3. alexr00 commented on Aug 24, 2021

    @alexr00
    Member

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

  4. karthiknadig commented on Aug 24, 2021

    @karthiknadig
    MemberAuthor

    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.

  5. karthiknadig commented on Aug 24, 2021

    @karthiknadig
    MemberAuthor

    Alex Ross (@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
    }
    
  6. DonJayamanne commented on Aug 24, 2021

    @DonJayamanne

    Verified

  7. alexr00 commented on Aug 25, 2021

    @alexr00
    Member

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

  8. removed their assignment
    on Aug 25, 2021
  9. locked as resolved and limited conversation to collaborators on Sep 25, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

      Milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions