-
Notifications
You must be signed in to change notification settings - Fork 1.2k
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
Python Testing: Codelens above parametrized tests doesn't open dropdown for selecting tests #8627
Comments
Fixes microsoft#8627. When the path of an actual test file (given by vscode.Uri.fsPath) is later compared against the fullPath of a single item of tests.TestFiles the drive letter mismatches and aborts further actions despite the rest of the path is the same.
Fixes microsoft#8627. When the path of an actual test file (given by vscode.Uri.fsPath) is later compared against the fullPath of a single item of tests.TestFiles the drive letter mismatches and aborts further actions despite the rest of the path is the same.
@phloose, thanks for letting us know about this and for being so proactive about finding a solution. Just to be sure I've understood, the problem is that the code lens tries to run a test with the wrong casing (for the drive letter)? This isn't specific to parameterized tests, is it? Also, popping up a picker UI for parameterized tests sounds more like a feature request. I recommend opening a separate issue for that one. |
This is how it used to behave (displaying a pocket for parameterized tests). Not sure what had changed in the extension. |
The problem i discovered is that the listed code tries to match a path (returned from
This applies ONLY to parametrized tests/tests that have a codelens that shows Run Test (Multiple), other tests work as expected.
Yeah i also remember that it worked correctly. In WSL/Linux and MacOS it works as expected. |
Fixes microsoft#8627. When the path of an actual test file (given by vscode.Uri.fsPath) is later compared against the fullPath of a single item of tests.TestFiles the drive letter mismatches and aborts further actions despite the rest of the path is the same.
Ah, thanks for clarifying. I was able to reproduce the problem using parameterized tests (only on WIndows). This is a know issue with VS Code. In the meantime, I expect the extension code needs to use FWIW, here's what I tried, with the following code in a top-level file: import pytest
@pytest.mark.parametrize('x,y,expected', [(1, 1, 2), (2, 3, 5)])
def test_add(x, y, expected):
assert x + y == expected LinuxTest discovery worked fine and the codelens showed up. When I clicked on WindowsTest discovery worked fine and the codelens showed up. When I clicked on |
Exactly as i discovered. This happens ONLY on Windows. For a possible fix look at my pull request #8647. It doesn't use that method (which just uppercases all path elements for the comparison when the platform is windows) but cuts of only the drive letter and uppercases that. There i should also add that this should only be done if the path is NOT relative, otherwise strange thinks happen... |
I've left a review on your PR. |
Fixes microsoft#8627. When the path of an actual test file (given by vscode.Uri.fsPath) is later compared against the fullPath of a single item of tests.TestFiles the drive letter mismatches on Windows and aborts further actions despite the rest of the path is the same. As a result code lenses on parametrized tests do not open a dropdown for selecting single tests.
Fixes microsoft#8627. When the path of an actual test file (given by vscode.Uri.fsPath) is later compared against the fullPath of a single item of tests.TestFiles the drive letter mismatches on Windows and aborts further actions despite the rest of the path is the same. As a result code lenses on parametrized tests do not open a dropdown for selecting single tests.
Expected behaviour
Clicking on the codelens above a parametrized test function/method or a whole test class (Run Test (Multiple) | Debug Test (Multiple)) opens a dropdown where one can select the test to run/debug.
Actual behaviour
When clicking on the codelens above a parametrized test function/method or a whole test class (Run Test (Multiple) | Debug Test (Multiple)) nothing happens.
Steps to reproduce:
On windows 10 (!):
Take any python package repository that contains tests and uses pytest, discover the tests and click on the appearing codelens above a parametrized test.
Note
There is no error message displayed in the various output panels (Protocol, Python Testing Log or others). Simply nothing happens.... Very confusing.
BUT!
While trying to find out the source of the error (because i like this codelens feature for running/debugging a single test very much) i cloned the vscode-python repo and set it up to debug the extension. I found out that the current code can't find a match between
fileName
anditem.name
oritem.fullPath
in the methoddisplayFunctionTestPickerUI
from the classTestDisplay
. In my casefileName
had the value c:\somepath\some_test_file.py anditem.fullPath
C:\somepath\some_test_file.py. The mismatch was the drive letter. When the drive letter is set to uppercase infileName
it works as expected and the dropdown menu is shown. OtherwisetestFile
is undefined an the method returns.Maybe this helps sorting out this bug. I did not find out exactly where the path from
tests.TestFiles[]
/item.fullPath
is generated but after some investigation i assume that it comes from thediscover
python module in the folder pythonFiles.Below the source code of that method:
Worth to mention that this works as expected when using vscode-python inside WSL.
The text was updated successfully, but these errors were encountered: