Skip to content

Debugging a test does not work in Testing tab #17399

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

Closed
jzazo opened this issue Sep 13, 2021 · 5 comments
Closed

Debugging a test does not work in Testing tab #17399

jzazo opened this issue Sep 13, 2021 · 5 comments
Assignees
Labels
area-testing bug Issue identified by VS Code Team member as probable bug info-needed Issue requires more information from poster

Comments

@jzazo
Copy link

jzazo commented Sep 13, 2021

Environment data

  • VS Code version: 1.60.0
  • Extension version: v2021.9.1215971179
  • OS and version: Ubuntu 20.04
  • Python version: Python 3.8.5 (pyenv 1.2.21)
  • Type of virtual environment used: pipenv, version 2018.11.26
  • Relevant/affected Python packages and their versions: pytest 6.2.5
  • Relevant/affected Python-related VS Code extensions and their versions: workspace configuration
  • Value of the python.languageServer setting: Pylance

Expected behaviour

I hit the Testing tab to find tests and click on Debug Test button on any test. I expect the test to run.

Actual behaviour

The testing wheel keeps turning and the test is never ran / debugged, e.g., by placing a breakpoint.

Steps to reproduce:

I have a repo structure as follows:

somerepo/:
  example1/
    .vscode/
      settings.json
    src/python/example/
      __init__.py
      example.py
    test/python/test_example/
      __init__.py
      test_example.py
  somerepo.code-workspace
  .envrc
  Pipfile
  Pipfile.lock

The contents of somerepo.code-workspace are:

{
    "folders": [
        {"path": "."},
        {"path": "example1"}
    ],
    "settings": {
        "files.exclude":{
            "example1": true
        },
        "python.languageServer": "Pylance"
    }
}

The contents of example1/.vscode/settings.json are:

{
    "python.envFile": "${workspaceFolder}/.envrc",
    "python.analysis.extraPaths": ["./src/python"],
    "python.pythonPath": "/home/javier/.local/share/virtualenvs/example1-CvWCFCrt/bin/python",
    "python.testing.pytestArgs": ["test"],
    "python.testing.unittestEnabled": false,
    "python.testing.pytestEnabled": true,
}

The contents of .envrc are:

layout pipenv

The contents of Pipfile are:

[[source]]
name = "pypi"
url = "https://pypi.org/simple"
verify_ssl = true

[dev-packages]
pytest = "*"

[packages]

[requires]
python_version = "3.8.5"

The contents of Pipfile.lock are generated by running pipenv install --dev.
The contents of example1/src/python/example/example.py are:

def hello():
    print("hello")

The contents of example1/test/python/example_test/test_example.py are:

def test_example1():
    assert True  # breakpoint here
@jzazo jzazo added bug Issue identified by VS Code Team member as probable bug triage-needed Needs assignment to the proper sub-team labels Sep 13, 2021
@karthiknadig karthiknadig self-assigned this Sep 13, 2021
@karthiknadig karthiknadig added area-testing triage and removed triage-needed Needs assignment to the proper sub-team labels Sep 13, 2021
@karthiknadig
Copy link
Member

I am not able to repro this.
image

I literally replicated what you have, and it seems to be working fine. Try enabling logs to see if something comes up. You can do this by setting logToFile true in the launch json.

{
    // Use IntelliSense to learn about possible attributes.
    // Hover to view descriptions of existing attributes.
    // For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387
    "version": "0.2.0",
    "configurations": [
        {
            "name": "Test config",
            "type": "python",
            "request": "launch",
            "purpose": ["debug-test"],
            "logToFile": true,
        }
    ]
}

Then start debugging using test explorer. Logs should in the extension folder (~/.vscode/extensions/ms-python.python-2021.9.1230869389) with the name debugpy*.log. Please share them.

The above config can only be used with tests and cannot be used to debug files using the play button. If you want to debug files using the play button, you can either use the debug button at the top of the file, or add a python file debug configuration in addition to the test config. Like this:

{
    // Use IntelliSense to learn about possible attributes.
    // Hover to view descriptions of existing attributes.
    // For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387
    "version": "0.2.0",
    "configurations": [
        {
            "name": "Python: Current File",
            "type": "python",
            "request": "launch",
            "program": "${file}",
            "console": "integratedTerminal"
        },
        {
            "name": "Test config",
            "type": "python",
            "request": "launch",
            "purpose": ["debug-test"],
            "logToFile": true
        }
    ]
}

@karthiknadig karthiknadig added the info-needed Issue requires more information from poster label Sep 14, 2021
@jzazo
Copy link
Author

jzazo commented Sep 15, 2021

Could the problem be that I am in a remote ssh session?
I activated the logs as you proposed, but the remote machine (Ubuntu 20.04) .vsode home folder only shows a settings.json file.
The local machine does not show any debugpy*.log files either in my home folder (Windows).
Can you try to repro in a remote machine? Otherwise, it seems that the debugging does not even start in my remote :S.

@karthiknadig
Copy link
Member

I tested this on ssh remote, it seems to be working there too. So I suspect debugger is somehow failing. The logs for ssh scenario will be under ~/.vscode-server/extensions/ms-python.python-2021.9.1230869389 or if you open Output > Python you should see path to the extension when we run linter or formatter or internal scripts to discover tests there. Just follow that path to the extension directory.

@jzazo
Copy link
Author

jzazo commented Sep 15, 2021

Apparently it seems to be working fine now, I don't know what has changed.
It is now working in the MWE and in my original repo too, so I cannot repro in either :S
Thanks a lot for your help, I will close this now, and reopen if it happens again.

@jzazo jzazo closed this as completed Sep 15, 2021
@ericchansen
Copy link

For me, I had to include "version": "0.2.0" in my launch.json to get it working. That isn't included in the automatically generated launch.json.

@github-actions github-actions bot locked as resolved and limited conversation to collaborators Dec 3, 2021
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 info-needed Issue requires more information from poster
Projects
None yet
Development

No branches or pull requests

3 participants