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

Debug output for test discovery has misleading argument #19820

Closed
JamesHutchisonCarta opened this issue Sep 13, 2022 · 4 comments
Closed

Debug output for test discovery has misleading argument #19820

JamesHutchisonCarta opened this issue Sep 13, 2022 · 4 comments
Assignees
Labels
area-testing bug Issue identified by VS Code Team member as probable bug

Comments

@JamesHutchisonCarta
Copy link

JamesHutchisonCarta commented Sep 13, 2022

Type: Bug

Behaviour

Expected vs. Actual

Expected:
The output found in "Python" when refreshing tests produces a verbatum command that can be copy and pasted into a terminal to reproduce an issue.

> /usr/local/bin/python ~/.vscode-remote/extensions/ms-python.python-2022.14.0/pythonFiles/testing_tools/run_adapter.py discover pytest -- --rootdir /workspaces/my-project -s --cache-clear --reuse-db
cwd: .

Actual:
The output has . as the --rootdir argument, but the actual argument passed in is a directory (likely the workspace one) with an absolute path

Example:

> /usr/local/bin/python ~/.vscode-remote/extensions/ms-python.python-2022.14.0/pythonFiles/testing_tools/run_adapter.py discover pytest -- --rootdir . -s --cache-clear --reuse-db
cwd: .

Steps to reproduce:

  1. Update the run_adapter.py file to add print(sys.argv). You might have to add the sys import
  2. Refresh tests. This print statement will bust the parser and it will display all output. You can see that sys.argv does not have . as the rootdir argument.
> /usr/local/bin/python ~/.vscode-server/extensions/ms-python.python-2022.14.0/pythonFiles/testing_tools/run_adapter.py discover pytest -- --rootdir . -s --cache-clear tests
cwd: .
[ERROR 2022-8-13 1:55:32.617]: Error discovering pytest tests:
 [SyntaxError: ['/home/vscode/.vscode-server/extensions/ms-python.python-2022.14.0/pythonFiles/testing_tools/run_adapter.py', 'discover', 'pytest', '--', '--rootdir', '/workspaces/my-project', '-s', '--cache-clear', 'tests']

Significance

When writing custom logic, the cwd . and the actual directory argument provided may technically be equivalent, but the test explorer will insert the absolute path in front of the source file's location when it parses the results as if it was a relative path if the path returned does not start with .

Example:
/workspaces/my-project/src/my-file.py

becomes

/workspaces/my-project/workspaces/my-project/src/my-file.py

Which then fails to open.

Diagnostic data

  • Python version (& distribution if applicable, e.g. Anaconda): 3.8.13
  • Type of virtual environment used (e.g. conda, venv, virtualenv, etc.): Global
  • Value of the python.languageServer setting: Default
Output for Python in the Output panel (ViewOutput, change the drop-down the upper-right of the Output panel to Python)

> /usr/local/bin/python ~/.vscode-remote/extensions/ms-python.python-2022.14.0/pythonFiles/testing_tools/run_adapter.py discover pytest -- --rootdir . -s --cache-clear --reuse-db
cwd: .

User Settings


languageServer: "Pylance"

linting
• flake8Enabled: true
• flake8Path: "<placeholder>"
• banditPath: "<placeholder>"
• mypyPath: "<placeholder>"
• pycodestylePath: "<placeholder>"
• pydocstylePath: "<placeholder>"
• pylintPath: "<placeholder>"

formatting
• autopep8Path: "<placeholder>"
• provider: "black"
• blackPath: "<placeholder>"
• yapfPath: "<placeholder>"

testing
• cwd: "<placeholder>"
• debugPort: 5678
• pytestArgs: "<placeholder>"
• pytestEnabled: true
• autoTestDiscoverOnSaveEnabled: false

Extension version: 2022.14.0
VS Code version: Code 1.70.2 (Universal) (e4503b30fc78200f846c62cf8091b76ff5547662, 2022-08-16T05:36:37.829Z)
OS version: Darwin x64 21.6.0
Modes:
Remote OS version: Linux x64 5.10.76-linuxkit
Remote OS version: Linux x64 5.4.0-1089-azure
Remote OS version: Linux x64 5.10.76-linuxkit
Remote OS version: Linux x64 5.10.76-linuxkit

A/B Experiments
vsliv368:30146709
vsreu685:30147344
python383cf:30185419
vspor879:30202332
vspor708:30202333
vspor363:30204092
vslsvsres303:30308271
pythonvspyl392:30443607
vserr242:30382549
pythontb:30283811
vsjup518:30340749
pythonptprofiler:30281270
vsdfh931cf:30280410
vshan820:30294714
vstes263cf:30335440
pythondataviewer:30285071
vscod805:30301674
binariesv615:30325510
bridge0708:30335490
bridge0723:30353136
cmake_vspar411:30557514
vsaa593cf:30376535
pythonvs932:30410667
cppdebug:30492333
pylanb8912:30545647
vsclangdf:30486550
c4g48928:30535728
hb751961:30553087
dsvsc012:30540252
azure-dev_surveyone:30548225
i497e931:30553904

@github-actions github-actions bot added the triage-needed Needs assignment to the proper sub-team label Sep 13, 2022
@JamesHutchisonCarta JamesHutchisonCarta changed the title Debug output for discovery has wrong directory Debug output for test discovery has misleading argument Sep 13, 2022
@karthiknadig karthiknadig added bug Issue identified by VS Code Team member as probable bug area-testing labels Sep 13, 2022
@eleanorjboyd
Copy link
Member

Hello! Thank you for submitting this bug, we appreciate your help. Do you notice this bug when you run both pytests and unittests or is it present on only one?

@eleanorjboyd eleanorjboyd added info-needed Issue requires more information from poster and removed triage-needed Needs assignment to the proper sub-team labels Sep 19, 2022
@JamesHutchisonCarta
Copy link
Author

I haven't tried unittests

@eleanorjboyd
Copy link
Member

Hello and sorry for the delay, this looks to be a bug in the test adapter that is likely related to the ongoing buggy behavior on pytest discovery and running in vscode. We are currently work on a rewrite of how pytest works in vscode and hope this rewrite will fix this and similar bugs. The main issue which will be working on is here: #17242, and progress will be updated on this issue. Thank you!

@brettcannon brettcannon removed the info-needed Issue requires more information from poster label Mar 2, 2023
@eleanorjboyd
Copy link
Member

Hi! This issue should be fixed with the rewrite that is released via an experiment. I would like to expand this to make it more comprehensive. I would like the logs to include a specific command you can copy and paste to run in the terminal. This will need to be delayed for an other fix which needs to be done first but I made this issue to track it.

@github-actions github-actions bot locked as resolved and limited conversation to collaborators Aug 10, 2023
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
Projects
None yet
Development

No branches or pull requests

4 participants