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

Cannot debug single unit test anymore #2241

Closed
F4h4D-T-Q opened this issue Jul 24, 2018 · 12 comments
Closed

Cannot debug single unit test anymore #2241

F4h4D-T-Q opened this issue Jul 24, 2018 · 12 comments
Assignees
Labels
area-debugging bug Issue identified by VS Code Team member as probable bug
Milestone

Comments

@F4h4D-T-Q
Copy link

Environment data

  • VS Code version: 1.25.1
  • Extension version (available under the Extensions sidebar): 2018.7.1
  • OS and version: Windows 7 (also tried on Windows 10)
  • Python version (& distribution if applicable, e.g. Anaconda): Python 3.6
  • Type of virtual environment used (N/A | venv | virtualenv | conda | ...): N/A
  • Relevant/affected Python packages and their versions: Unit Testing

Actual behavior

Clicking on the 'Debug Test' link of a unit test method (not class!) results in all the unit tests of that class to execute.
Quick analysis:
The problem stems from the code change in #2066 on line 300, where a 'break' has been added in the first condition. Removing this makes the code work as before.

It also seems that the second condition (line 301) will never be reached due to this 'break'. This is because the first condition (line 298) is a more lenient check and will always be true when the second more stricter check is true. Unfortunately due to the 'break' the first condition will assign the whole class as the desired tests instead of the single test, which is assigned if he second condition is true.

Expected behavior

Only the selected unit test method should execute, as was the case earlier.

Steps to reproduce:

  1. Create a unit test class (derived from unittest.TestCase)
  2. Create a couple of unit test methods.
  3. Assuming that the unit tests are discovered and the 'Run Test| Debug Test' links are visible, click on the Debug Test link of a method. --> All the Unit tests execute instead of only the desired test.

Logs

Output for Python in the Output panel (ViewOutput, change the drop-down the upper-right of the Output panel to Python)

N/A, please see issue above

Output from Console under the Developer Tools panel (toggle Developer Tools on under Help)

N/A, please see issue above
@brettcannon brettcannon added bug Issue identified by VS Code Team member as probable bug needs verification area-debugging labels Jul 24, 2018
@ryannathans
Copy link

I have the same issue when clicking "Run Test" - all tests in the class are executed. This feature used to work correctly.

@brettcannon
Copy link
Member

Is this with the new language server or Jedi?

@F4h4D-T-Q
Copy link
Author

F4h4D-T-Q commented Jul 26, 2018

I don't have any Jedi extension installed. In the 'Actual behavior' section I have given the link to the changelist (affected file) and more specifically the file "pythonFiles/PythonTools/visualstudio_py_testlauncher.py". Don't know if that helps.

@brettcannon
Copy link
Member

@F4h4D-T-Q I was actually asking if you have "python.jediEnabled": false set? But thanks for the code diagnosis and we will look into it.

@d3r3kk
Copy link

d3r3kk commented Jul 26, 2018

Apologies for the breakage, I'd added that to handle a different problem and had missed some other cases I wasn't focusing on. We'll get a fix for it for the next release.

...and perhaps add some testing for our Python files!

@F4h4D-T-Q
Copy link
Author

@brettcannon : "python.jediEnabled": true. Sorry for not understanding your question, I only recently started using Visual Studio Code (and think it's great!) so still a lot to learn and discover.

@d3r3kk
Copy link

d3r3kk commented Jul 30, 2018

I can repro this issue.

Using this code file:

import unittest

class Issue2241(unittest.TestCase):

    def test_somthing(self):
        self.assertEqual(1, 2, 'nah')
    

    def test_somethingElse(self):
        self.assertFalse(True, 'nah nah')


if __name__ == '__main__':
    unittest.main()

...and ensuring that the python.jediEnabled setting in the user settings is set to true.

Wait until the run test code lense appears and click it, and you will note in the Console window (Under the Output->Python Test Log window pane) that it does indeed run the two.

Note: I commented out the break in visualstudio_py_testLauncher.py, line 300, to see if the problem would be rectified, and it did not.

@F4h4D-T-Q
Copy link
Author

F4h4D-T-Q commented Jul 31, 2018

I copied the class above, followed the same steps as mentioned, and could successfully run only the desired test. That is only afer I have the break commented out in (line 300, visualstudio_py_testLauncher.py) so I'm surprised why we are observing different behavior.

I don't know if this helps but here is my debug configuration:

       {
           "name": "Python Experimental: Current File (Integrated Terminal)",
            "type": "pythonExperimental",
            "request": "launch",
            "program": "${file}",
            "console": "integratedTerminal"
        }

and here are the workspace settings:

{
    "python.unitTest.unittestArgs": [
        "-v",
        "-s",
        ".",
        "-p",
        "test_*.py"
    ],
    "python.unitTest.pyTestEnabled": false,
    "python.unitTest.nosetestsEnabled": false,
    "python.unitTest.unittestEnabled": true
}

@F4h4D-T-Q F4h4D-T-Q reopened this Jul 31, 2018
@DonJayamanne
Copy link

@F4h4D-T-Q
Please could you add the following setting and try once again:

"python.unitTest.useExperimentalDebugger": true

With this setting in place, the unit tests will be debugged using the experimental debugger.

@F4h4D-T-Q
Copy link
Author

@DonJayamanne , same result: only the desired test case executes. The only difference I saw was that the Debug Console now shows output in a different color (brownish orange).

@brettcannon brettcannon added this to the Aug 2018 milestone Aug 2, 2018
@d3r3kk
Copy link

d3r3kk commented Aug 3, 2018

I copied the class above, followed the same steps as mentioned, and could successfully run only the desired test. That is only afer I have the break commented out in (line 300, visualstudio_py_testLauncher.py) so I'm surprised why we are observing different behavior.

Tried again this morning - you are correct and the behaviour is now correct for me too. 100% I didn't reload my environment before attempting the test last time!

d3r3kk added a commit to d3r3kk/vscode-python that referenced this issue Aug 3, 2018
- do not break after discovering suite, still check for individual tests
- fix for issue microsoft#2241
@d3r3kk
Copy link

d3r3kk commented Aug 8, 2018

Should be fixed in the next release.

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

No branches or pull requests

5 participants