Skip to content

Debugging unittest tests doesn't work #89

Closed

Description

From @yRefl3x on March 6, 2017 11:11

Environment data

VS Code version: 1.10.1
Python Extension version: 0.5.9
Python Version: 2.7.5
OS and version: Windows 10

Actual behavior

After clicking on the "Debug Test" lens of a test method, debugging doesn't start. "Running Tests" is displayed at the bottom of the VSCode window indefinitely.

Expected behavior

Debugging starts.

Steps to reproduce:

I have the following folder structure:

Issue
    cool_package
        __init__.py
        cool_module.py
    test
        __init__.py
        test_cool_module.py

cool_module.py

def foo(a, b):
    return a + b

test_cool_module.py

import unittest

from cool_package.cool_module import foo

class TestCoolModule(unittest.TestCase):
    def test_foo(self):
        res = foo(1, 2)
        self.assertEquals(res, 3)
  • Set a breakpoint at line res = foo(1, 2)
  • Click "Debug Test" in test method code lens

Settings

settings.json:

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

Logs

Output from Python Test Log output panel

READY

Copied from original issue: DonJayamanne/pythonVSCode#797

Activity

  1. DonJayamanne commented on Nov 13, 2017

    @DonJayamanne
    Author

    From Stav (@syagev) on March 14, 2017 8:56

    Same exact symptoms here.
    win10, python ext 0.6.0, VSC 1.10.2, Python 3.5.3

    EDIT: "reload window" VSC command seems to solve this every time this happens

  2. DonJayamanne commented on Nov 13, 2017

    @DonJayamanne
    Author

    From @yRefl3x on March 14, 2017 9:56

    Stav (@syagev) I just tried reloading the window before debugging as you suggested. The test actually runs, but it doesn't debug. The breakpoint just changes to a grey circle for a short time but execution isn't stopped. The test just runs like when choosing "Run Tests".

  3. DonJayamanne commented on Nov 13, 2017

    @DonJayamanne
    Author

    From Alex Whittemore (@alexwhittemore) on March 29, 2017 17:14

    Confirmed, but I can't try "reload window" to solve it, because "discovering tests" has stopped completing for me.

  4. DonJayamanne commented on Nov 13, 2017

    @DonJayamanne
    Author

    From Guilherme Passero (@gpassero) on April 1, 2017 14:5

    I can debug tests when I run them with the following command line (in the end of the test file script). It may be a temporary solution for you.

    if __name__ == '__main__':
        unittest.main()
    
  5. DonJayamanne commented on Nov 13, 2017

    @DonJayamanne
    Author

    From Alex Whittemore (@alexwhittemore) on April 1, 2017 15:59

    Update: I can get unit tests to discover if I run "discover unit tests," then, while it works, run "run all tests," which causes discovery to alert failure. At this point, I can "run unit tests", which will trigger discovery successfully. At least, I think that's the flow. Will verify back at a computer.

  6. DonJayamanne commented on Nov 13, 2017

    @DonJayamanne
    Author

    From Larry & Leo (@xqliu) on April 18, 2017 16:55

    Alex Whittemore (@alexwhittemore) How did you run "discover unit tests"? method?

    I can not find this command on the command panel nor any place ...

    Thanks :)

  7. DonJayamanne commented on Nov 13, 2017

    @DonJayamanne
    Author

    From Alex Whittemore (@alexwhittemore) on April 18, 2017 18:25

    In the bottom bar, bottom left, where it usually says "run tests" - I think it'll say "discovery failed" when such is the case, and clicking it will bring up the command palette with an option to discover.
    capture

  8. DonJayamanne commented on Nov 13, 2017

    @DonJayamanne
    Author

    Alex Whittemore (@alexwhittemore) Sorry, please run the command Run All Unittests

  9. DonJayamanne commented on Nov 13, 2017

    @DonJayamanne
    Author

    From @VicLiang621 on May 28, 2017 7:38

    I have a similar issue where when you click "Debug test" the running tests never stop and breakpoints do not matter. When trying to implement the if __name__ == '__main__': unittest.main(), seems to be a temporary fix.
    image

  10. DonJayamanne commented on Nov 13, 2017

    @DonJayamanne
    Author

    From sdtom on June 19, 2017 15:6

    Similar issue, my workaround.. keep clicking "debug test" over and over.. first time gets READY, second time generates an error.. but maybe 1 out of 10 times instead of just getting READY, things turn orange and debugging works fine

  11. DonJayamanne commented on Nov 13, 2017

    @DonJayamanne
    Author

    From Matt Morgis (@mattmorgis) on July 22, 2017 0:56

    I am having the same issue with both the unittest and pytest options, both generate the same error. If you can point me in the right direction, I can get a fix merged in.

    I created a sample project to help identify the issue: https://github.com/MattMorgis/python-tests

    Each time I hit Debug Test inline in VS Code, I get this output:

    FAILED (errors=1)
    Traceback (most recent call last):
      File "/Users/morgism/.vscode/extensions/donjayamanne.python-0.6.9/pythonFiles/PythonTools/visualstudio_py_testlauncher.py", line 343, in <module>
        main()
      File "/Users/morgism/.vscode/extensions/donjayamanne.python-0.6.9/pythonFiles/PythonTools/visualstudio_py_testlauncher.py", line 238, in main
        enable_attach(opts.secret, ('127.0.0.1', getattr(opts, 'port', DEFAULT_PORT)), redirect_output = True)
      File "/Users/morgism/.vscode/extensions/donjayamanne.python-0.6.9/pythonFiles/PythonTools/ptvsd/attach_server.py", line 167, in enable_attach
        server.bind(address)
      File "/Users/morgism/anaconda/envs/py2Env/lib/python2.7/socket.py", line 228, in meth
        return getattr(self._sock,name)(*args)
    socket.error: [Errno 48] Address already in use
    

    I am using a conda environment and have my Python path set both in settings.json and as an ENV variable. pytest is installed there when trying to run that configuration.

  12. 19 remaining items

  13. thomsavage commented on Feb 16, 2018

    @thomsavage

    I think I'm still seeing this issue. Trying to use the inline "Debug Tests" within a unit test module shows "Running Tests" in the status bar, but nothing happens.

    • VSCode 1.20.1 x64
    • Python 2018.1.0
    • Win 10
  14. veuncent commented on Mar 9, 2018

    @veuncent

    I have the same issue and same versions as Thom Savage (@thomsavage) lists (except my Python extension = 2018.2.0).

    Edit: although I use nose instead of unittest:

    {
        "python.unitTest.nosetestsEnabled": true,  
        "python.unitTest.unittestEnabled": false,  
        "python.unitTest.pyTestEnabled": false,  
        "python.unitTest.promptToConfigure": true,  
    }
    

    But the same problem persist if I only enable unittestEnabled.

  15. brettcannon commented on Mar 9, 2018

    @brettcannon
    Member

    Vincent Meijer (@veuncent) so you're saying that your example config is fine but it becomes an issue if you set "python.unitTest.unittestEnabled": true" while having "python.unitTest.nosetestsEnabled": true` as well? IOW what is the exact setting you have which consistently triggers the problem?

  16. veuncent commented on Mar 9, 2018

    @veuncent

    Brett Cannon (@brettcannon) No that's not what I mean. Under no circumstances debugging works. I tried having only one of the testing frameworks enabled at a time (as well as having multiple enabled, which obviously shouldn't work).

    Clicking Debug Test above a test class or method does nothing, besides showing the Running Tests throbber at the bottom of the window.

  17. veuncent commented on Mar 9, 2018

    @veuncent

    P.s. When I add

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

    to the bottom of the file I can use the Start Debugging button in VSC to run the unit tests, but it does not pause at break points or anything.

  18. DonJayamanne commented on Mar 9, 2018

    @DonJayamanne
    Author

    Vincent Meijer (@veuncent) Please could you create a separate issue with a sample code that we can use to replicate this at our end.
    If you can point us to a git repo that would be great.
    Please provide the following info in the new issue:

    • Python version
    • OS version
    • Sample code to replicate this issue
  19. veuncent commented on Mar 9, 2018

    @veuncent

    Done: #1009

  20. locked as resolved and limited conversation to collaborators on Jul 11, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

      Milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions