Skip to content

Debugging test in VS Code does not work #10722

Closed as not planned
Closed as not planned

Description

@asipras

Environment data

Version: 1.43.1 (user setup)
Commit: fe22a9645b44368865c0ba92e2fb881ff1afce94
Date: 2020-03-18T07:01:20.184Z
Electron: 7.1.11
Chrome: 78.0.3904.130
Node.js: 12.8.1
V8: 7.8.279.23-electron.0
OS: Windows_NT x64 10.0.18363

  • Python version (& distribution if applicable, e.g. Anaconda): Python Anaconda 3.7.6 64-bit
  • Type of virtual environment used (N/A | venv | virtualenv | conda | ...): Anaconda 1.9.12
  • Relevant/affected Python packages and their versions: Python 2020.3.69010
  • Relevant/affected Python-related VS Code extensions and their versions: Python 2020.3.69010

Expected behaviour

Debugging test should work.

Actual behaviour

Debugging test does not work. VS code shows error dialog. See in reproduction steps for more details. If I run the test without debugger the tests runs as expected.

Steps to reproduce:

Try to debug tests using unit test library, Click on the small bug icon for an individual test to debug.
I get a dialog box error saying Invalid message: Duplicate entries in "env". The two options i get are Open launch.json and Cancel.

I have checked my lauch.json and I do not have duplicate entries for any env variable.

Logs

ERR timeout after 500 ms: Error: timeout after 500 ms
at t.RawDebugSession.handleErrorResponse (file:///C:/Users/AP/AppData/Local/Programs/Microsoft VS Code/resources/app/out/vs/workbench/workbench.desktop.main.js:2954:952)
at file:///C:/Users/AP/AppData/Local/Programs/Microsoft VS Code/resources/app/out/vs/workbench/workbench.desktop.main.js:2954:250
at async t.RawDebugSession.shutdown (file:///C:/Users/AP/AppData/Local/Programs/Microsoft VS Code/resources/app/out/vs/workbench/workbench.desktop.main.js:2952:336)

### Settings.json

{
    "python.testing.pytestArgs": [
        "tests"
    ],
    "python.testing.unittestEnabled": false,
    "python.testing.nosetestsEnabled": false,
    "python.testing.pytestEnabled": true
}

Activity

  1. added
    triage-needed
    bug
    on Mar 23, 2020
  2. ghost removed
    triage-needed
    on Mar 23, 2020
  3. lorenzo-cavazzi commented on Mar 24, 2020

    @lorenzo-cavazzi
  4. kimadeline commented on Mar 24, 2020

    @kimadeline

    Hello Asif (@asipras) and Lorenzo Cavazzi (@lorenzo-cavazzi), thank you for reaching out.

    Can I ask you both to provide the following:

    • A sample repo (just the .vscode/settings.json is sadly not enough for me to replicate this issue, I can debug tests correctly);
    • The content of the Python output panel (View→Output, change the drop-down the upper-right of the Output panel to Python).

    Can you also confirm that if you downgrade to the previous release of the extension (2020.2.64397) you can debug tests correctly:

    image

    Lorenzo Cavazzi (@lorenzo-cavazzi) what do you mean by that:

    For some reason, trying to install a different version of the Python extension doesn't work.

    Thanks!

  5. added
    info-needed
    on Mar 24, 2020
  6. asipras commented on Mar 24, 2020

    @asipras
    Author

    Kim-Adeline Miguel (@kimadeline) thanks for looking into this. I did downgrade to the previous version of python extension 2020.2.64397 and now i am able to debug the tests.

    I also did some debugging with the latest version of python extension 2020.3.69010. I was able to debug a simple test (does not reference any 3rd party modules numpy, scipy, etc.) by invoking VS code from normal command prompt. However when I invoked VS code using Anaconda prompt/terminal I got the error message mentioned above.

    The log from the python output panel.

    > ~\Anaconda3\envs\mounthood-dev\python.exe -m site --user-site
    cwd: c:\src\Test
    > ~\Anaconda3\envs\mounthood-dev\python.exe -m site --user-site
    cwd: c:\src\Test
    > ~\Anaconda3\envs\mounthood-dev\python.exe completion.py
    cwd: c:\Users\asif.prasla\.vscode\extensions\ms-python.python-2020.3.69010\pythonFiles
    > ~\Anaconda3\envs\mounthood-dev\python.exe completion.py
    cwd: c:\Users\asif.prasla\.vscode\extensions\ms-python.python-2020.3.69010\pythonFiles
    > ~\Anaconda3\envs\mounthood-dev\python.exe -m pylint --disable=all --enable=F,unreachable,duplicate-key,unnecessary-semicolon,global-variable-not-assigned,unused-variable,unused-wildcard-import,binary-op-exception,bad-format-string,anomalous-backslash-in-string,bad-open-mode,E0001,E0011,E0012,E0100,E0101,E0102,E0103,E0104,E0105,E0107,E0108,E0110,E0111,E0112,E0113,E0114,E0115,E0116,E0117,E0118,E0202,E0203,E0211,E0213,E0236,E0237,E0238,E0239,E0240,E0241,E0301,E0302,E0303,E0401,E0402,E0601,E0602,E0603,E0604,E0611,E0632,E0633,E0701,E0702,E0703,E0704,E0710,E0711,E0712,E1003,E1101,E1102,E1111,E1120,E1121,E1123,E1124,E1125,E1126,E1127,E1128,E1129,E1130,E1131,E1132,E1133,E1134,E1135,E1136,E1137,E1138,E1139,E1200,E1201,E1205,E1206,E1300,E1301,E1302,E1303,E1304,E1305,E1306,E1310,E1700,E1701 --msg-template='{line},{column},{category},{symbol}:{msg}' --reports=n --output-format=text c:\src\Test\tests\test_one.py
    cwd: c:\src\Test
    > ~\Anaconda3\envs\mounthood-dev\python.exe -m pylint --disable=all --enable=F,unreachable,duplicate-key,unnecessary-semicolon,global-variable-not-assigned,unused-variable,unused-wildcard-import,binary-op-exception,bad-format-string,anomalous-backslash-in-string,bad-open-mode,E0001,E0011,E0012,E0100,E0101,E0102,E0103,E0104,E0105,E0107,E0108,E0110,E0111,E0112,E0113,E0114,E0115,E0116,E0117,E0118,E0202,E0203,E0211,E0213,E0236,E0237,E0238,E0239,E0240,E0241,E0301,E0302,E0303,E0401,E0402,E0601,E0602,E0603,E0604,E0611,E0632,E0633,E0701,E0702,E0703,E0704,E0710,E0711,E0712,E1003,E1101,E1102,E1111,E1120,E1121,E1123,E1124,E1125,E1126,E1127,E1128,E1129,E1130,E1131,E1132,E1133,E1134,E1135,E1136,E1137,E1138,E1139,E1200,E1201,E1205,E1206,E1300,E1301,E1302,E1303,E1304,E1305,E1306,E1310,E1700,E1701 --msg-template='{line},{column},{category},{symbol}:{msg}' --reports=n --output-format=text c:\src\Test\tests\test_one.py
    cwd: c:\src\Test
    > conda env list
    ##########Linting Output - pylint##########
    
    --------------------------------------------------------------------
    
    Your code has been rated at 10.00/10 (previous run: 10.00/10, +0.00)
    
    
    
    > ~\Anaconda3\envs\mounthood-dev\python.exe c:\Users\asif.prasla\.vscode\extensions\ms-python.python-2020.3.69010\pythonFiles\testing_tools\run_adapter.py discover pytest -- --rootdir c:\src\Test -s --cache-clear tests
    cwd: c:\src\Test
    > ~\Anaconda3\envs\mounthood-dev\python.exe -c "import notebook"
    > ~\Anaconda3\envs\mounthood-dev\python.exe -c "import jupyter"
    

    image

  7. lorenzo-cavazzi commented on Mar 24, 2020

    @lorenzo-cavazzi
  8. lorenzo-cavazzi commented on Mar 24, 2020

    @lorenzo-cavazzi
  9. kimadeline commented on Mar 24, 2020

    @kimadeline

    Asif (@asipras) Can you add the following configuration to your launch.json:

            {
                "name": "Python: Test debug config",
                "type": "python",
                "request": "test",
                "console": "integratedTerminal",
                "logToFile": true
            }

    Try debugging your tests, and copy here the content of the debugpy*.log file from the extension folder.

    Lorenzo Cavazzi (@lorenzo-cavazzi) are you getting the same Duplicate entries in "env" message? If that's the case, there is something else going on in your setup that's not related to the extension, because it's a Windows-specific error message from the debugger:

    https://github.com/microsoft/debugpy/blob/69db68a5f9aff6c1dfd955c8934c753212f94633/src/debugpy/launcher/handlers.py#L110-L119

  10. lorenzo-cavazzi commented on Mar 25, 2020

    @lorenzo-cavazzi
  11. lorenzo-cavazzi commented on Mar 25, 2020

    @lorenzo-cavazzi
  12. lorenzo-cavazzi commented on Mar 25, 2020

    @lorenzo-cavazzi
  13. 55 remaining items

  14. plaa commented on Aug 22, 2023

    @plaa

    I just hit the same problem, running tests works fine but debugging a test fails with ModuleNotFoundError: No module named 'my_main_module'

    I tested older versions and v2023.8.0 and older work:

    v2023.14.0 Debugging tests fail ❌
    v2023.12.0 Debugging tests fail ❌
    v2023.10.1 Unittest discovery fails with ModuleNotFoundError: No module named 'my_main_module' ❌
    v2023.10.0 Unittest discovery fails with ModuleNotFoundError: No module named 'my_main_module' ❌
    v2023.8.0 (and older) work as expected ✅

  15. karrtikr commented on Sep 12, 2023

    @karrtikr

    Activation issues related to debugging tests were recently fixed, try using the latest version of VS Code and Python extension. cc/ Sampo Juustila (@plaa)

  16. eleanorjboyd commented on Oct 30, 2023

    @eleanorjboyd

    Hello! I have reviewed this issue and given the architectural changes of the testing rewrite, this issue should no longer exist on the rewrite. Therefore I am going to close this issue but please comment or open a new issue if you are still seeing a problem when you try this yourself!

    To use the rewrite yourself just add ”python.experiments.optInto": ["pythonTestAdapter"] to your user settings. You can confirm you have the rewrite enabled by setting your log level to trace, via the Developer: Set Log Level command in the command palette. Then check to see if Experiment 'pythonTestAdapter' is active is in your python logs.

    Thanks!

  17. removed
    needs PR
    on Oct 30, 2023
  18. immanuelazn commented on Nov 20, 2023

    @immanuelazn

    Hi, I've noticed a separate issue when interfacing with Azure credentials now.

    Debugging appears to work, however it appears that the behavior is now different than how a traditional "run" in a test would work. In my case, DefaultAzureCredentials() does not function correctly and throws an error, but works in run mode within the tests window. I have also used with and without ”python.experiments.optInto": ["pythonTestAdapter"], confirmed with the new test adapter.
    The following versions have been tested

    • PreRelease: Not working with and without test adapter
    • 2023.20.0: Not working with and without test adapter
    • Every version between 2023.20.0 and 2023.8.0: Not working without test adapter.
    • 2023.8.0: Working as expected
  19. eleanorjboyd commented on Nov 27, 2023

    @eleanorjboyd

    hello Immanuel Abdi (@immanuelazn), would you be able to create a new issue with the information so we can triage it and better understand the issue? Thanks!

  20. schwaerz commented on Dec 19, 2023

    @schwaerz

    To me this issue does not seem to be fixed.
    I am currently running v2023.22.1 of the plugin together with behave.

    Error message is exaclty the same one as reported initially.

    When I downgrade to 2023.8.0 it will work again.

    The following did not help:

    "python.experiments.optInto": ["pythonTestAdapter"]
    
  21. locked as resolved and limited conversation to collaborators on Jan 19, 2024
  22. eleanorjboyd commented on Jan 25, 2024

    @eleanorjboyd

    Jörg Schwärzler (@schwaerz) are you still experiencing this issue? Could you describe your project structure and include your logs so we can take a closer look? Thanks

  23. added
    triage-needed
    on Jan 25, 2024
  24. eleanorjboyd commented on Dec 10, 2024

    @eleanorjboyd

    closing as stale

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Labels

area-debuggingarea-environmentsarea-testingbugtriage-needed

Type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions