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

VSCode-Python/unittest module invoking wrong TestCase? #10972

Closed
alabasterfox opened this issue Apr 5, 2020 · 2 comments · Fixed by #16769
Closed

VSCode-Python/unittest module invoking wrong TestCase? #10972

alabasterfox opened this issue Apr 5, 2020 · 2 comments · Fixed by #16769
Labels
area-testing bug Issue identified by VS Code Team member as probable bug verified Verification succeeded
Milestone

Comments

@alabasterfox
Copy link

Environment data

  • VS Code version: 1.40.2
  • Extension version (available under the Extensions sidebar): 2020.2.64397 (21 February 2020)
  • OS and version: Linux x64 3.10.0-1062.el7.x86_64
  • Python version (& distribution if applicable, e.g. Anaconda): Python 3.6
  • Type of virtual environment used (N/A | venv | virtualenv | conda | ...): virtualenv (also tested N/A)
  • Relevant/affected Python packages and their versions: unittest (deploys with python)

Expected behaviour

As a User, in the Test Panel of VSCode, with the 3 TestCases USER_STORY_1_8_1, USER_STORY_1_8_10, and USER_STORY_1_8_11 present, when I click the run or debug icon associated with a TestCase named USER_STORY_1_8_1, TestCase USER_STORY_1_8_1 is run/debugged.

Actual behaviour

As a User, in the Test Panel of VSCode, with the 3 TestCases USER_STORY_1_8_1, USER_STORY_1_8_10, and USER_STORY_1_8_11 present , when I click the run or debug icon associated with a TestCase named USER_STORY_1_8_1, TestCase USER_STORY_1_8_11 is run/debugged. If USER_STORY_1_8_11 is unavailable (e.g. commented out), USER_STORY_1_8_10 is run/debugged. And if neither is available, only then is USER_STORY_1_8_1 run/debugged.

Unexpeced_behavior

Steps to reproduce:

  1. Create the a new VSCode project with a file named test.py and copy and paste in the following simple code:
import unittest

class USER_STORY_1_8_1(unittest.TestCase):

    def setUp(self):
        print('USER_STORY_1_8_1:setUp')

    def tearDown(self):
        print('USER_STORY_1_8_1:tearDown')

    def test_run(self):
        print('USER_STORY_1_8_1:test_run')

class USER_STORY_1_8_10(unittest.TestCase):

    def setUp(self):
        print('USER_STORY_1_8_10:setUp')

    def tearDown(self):
        print('USER_STORY_1_8_10:tearDown')

    def test_run(self):
        print('USER_STORY_1_8_10:test_run')

class USER_STORY_1_8_11(unittest.TestCase):

    def setUp(self):
        print('USER_STORY_1_8_11:setUp')

    def tearDown(self):
        print('USER_STORY_1_8_11:tearDown')

    def test_run(self):
        print('USER_STORY_1_8_11:test_run')

test.py

  1. Configure VSCode to use a python interpreter for execution and the unittest framework for testing.
    When configuring the unittest framework, configure auto-discover to search for files with the pattern test*.py

  2. On the left sidebar click the Chemistry flask icon to open the Test Panel of VSCode. The 3 unit tests will be auto-discovered and populated in the list under test.py

  3. Go to the TestCase named USER_STORY_1_8_1 and click the run icon or debug icon associated with it to attempt to run it or debug it

Issue is encountered: TestCase USER_STORY_1_8_11 will be run or debugged instead of the target USER_STORY_1_8_1 TestCase

I have a corresponding stackoverflow question open here: https://stackoverflow.com/questions/61048113/python-unittest-module-invoking-wrong-class where another user confirmed seeing the same behavior and proposed opening an Issue Report

@alabasterfox alabasterfox added triage-needed Needs assignment to the proper sub-team bug Issue identified by VS Code Team member as probable bug labels Apr 5, 2020
@alabasterfox alabasterfox changed the title VSCode-Python unittest module invoking wrong class? VSCode-Python/unittest module invoking wrong TestCase? Apr 5, 2020
@ghost ghost removed the triage-needed Needs assignment to the proper sub-team label Apr 7, 2020
@karrtikr
Copy link

karrtikr commented Apr 8, 2020

I can confirm the bug, thanks! As quoted in stack overflow, Please consider using a different test framework as a workaround. I've checked the same code but running it with the pytest framework and all tests run without any issues.

@karrtikr karrtikr removed their assignment Apr 8, 2020
@karthiknadig karthiknadig added the verified Verification succeeded label Jul 29, 2021
@karthiknadig
Copy link
Member

This is addressed by #16769 Clicking run on USER_STORY_1_8_1 runs just that.

image

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
area-testing bug Issue identified by VS Code Team member as probable bug verified Verification succeeded
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants