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

Run Test | Debug Test disappear on save, then re-appear when tabbing on/off the file. #2790

Closed
amittleider opened this issue Oct 4, 2018 · 25 comments · Fixed by #16769
Closed
Labels
area-testing bug Issue identified by VS Code Team member as probable bug verified Verification succeeded
Milestone

Comments

@amittleider
Copy link

amittleider commented Oct 4, 2018

vscode_weird_test_button_behavior

Environment data

  • VS Code version: 1.27.2
  • Extension version (available under the Extensions sidebar): 2018.8.0
  • OS and version: Ubuntu 16.04
  • Python version (& distribution if applicable, e.g. Anaconda): Python 3.6.3
  • Type of virtual environment used (N/A | venv | virtualenv | conda | ...): venv

Actual behavior

I have 2 files, test_vscode1.py and test_vscode2.py. I first discover the unit tests to get the Run Test | Debug Test buttons. Next, I remove the i = 0 line and re-save the file. The Run Test | Debug Test disappears permanently if I stay on this file. Next, I tab to the test_vscode1.py file and back to the test_vscode2.py file and the Run Test | Debug Test buttons re-appear.

Expected behavior

Don't make the Run Test | Debug Test buttons disappear on save.

Steps to reproduce:

  1. See the description above

Logs

Output for Python in the Output panel (ViewOutput, change the drop-down the upper-right of the Output panel to Python)

Just a bunch of nose discovery stuff, don't think it's useful

Output from Console under the Developer Tools panel (toggle Developer Tools on under Help)

devlogs.txt

@brettcannon brettcannon added bug Issue identified by VS Code Team member as probable bug needs verification area-testing labels Oct 4, 2018
@DonJayamanne
Copy link

I'm unable to replicate this issue.
Please could you provide a sample repo I can use to replicate this at my end.

@DonJayamanne DonJayamanne added info-needed Issue requires more information from poster and removed needs verification labels Oct 18, 2018
@amittleider
Copy link
Author

Thanks for taking a look @DonJayamanne .

I have set up a repro in this repo: https://github.com/amittleider/vscode_python_bug_repro .

Here are the steps:

cd ~/mysource
git clone git@github.com:amittleider/vscode_python_bug_repro.git
pip install -e vscode_python_bug_repro

Next, open VScode and use the "Add folder to workspace" and select the folder ~/mysource/vscode_python_bug_repro/vscode_python_bug_repro_lib.

Next, set your workspace settings to the following json:

{
	"folders": [
		{
			"path": "/home/mitt/source/vscode_python_bug_repro/vscode_python_bug_repro_lib"
		}
	],
	"settings": {}
}

Set your user settings to the following json:

{
    "python.unitTest.nosetestsEnabled": true,
    "python.unitTest.autoTestDiscoverOnSaveEnabled": false,
    "editor.fontSize": 12,
    "window.zoomLevel": 0,
    "breadcrumbs.enabled": true,
    "workbench.editor.enablePreview": false,
    "editor.wordBasedSuggestions": false,
}

Next, use the VScode console to "Discover Unit Tests", like the gif below.
discover

Next, hopefully you will see the bug as well. Here is a gif of the bug repro using the repository I made.
vscode_bug_repro

@DonJayamanne
Copy link

Sorry still unable to replicate this issue at my end.
dbg_ux

@amittleider
Copy link
Author

amittleider commented Nov 13, 2018

Is there any more information that I can give to help?

I have updated my version of the extension and the version of the VSCode today. Unfortunately the problem is worse -- Now I never see the Code Lens for Run Tests | Debug Tests, no matter what.

There is another bug open on the issue here: #2908 . The difference is that my tests have no types in them (although the code that runs inside of the tests are typed).

Below is a new gif. I begin by discovering unit tests, but no code lens shows up. Then I run the current unit test file, which succeeds. Then I debug the current unit test, which hits the breakpoint properly.

nocodelens

VSCode version: 1.29.0
VScode Python version: 2018.10.1
Ubuntu 18.04

@DonJayamanne
Copy link

Could you edit the file (add an empty line), then close and re-open the file.

@amittleider
Copy link
Author

amittleider commented Nov 14, 2018

I tried to add some new lines, close, and re-open, but it didn't work. I also tried to disabled the C#, C++, and Docker extensions for my workspace (now I just have your Python extension and a VS keymap enabled for this workspace), and it looks like I'm back to the behavior that I originally posted on Oct 4 (Run Test | Debug Test code lens appears when you arrive on the file, but if you save, it disappears).

I had a debugging session today on the issue. It appears to me the problem is coming from testFiles.ts line 72.

const symbols = (await symbolProvider.provideDocumentSymbols(document, token)) as SymbolInformation[];

When I tab onto the file (the case where Run Tests | Debug Tests appears properly), the symbols variable is properly populated. When I save the file (the case where Run Tests | Debug Tests disappears), the symbols variable an empty array, so the getCodeLens function will never be called. I get a bit lost going into the symbolProvider code.

@rspeer
Copy link

rspeer commented Nov 14, 2018

This is happening to me too, whenever I edit a test file.

Is there a way to simply disable the test code lens? I know #1654 asked for it but you declined it because it was asking two things at the same time.

@DonJayamanne
Copy link

@amittleider
Please could you try adding the following setting into your settings.json file:
"python.jediEnabled":false
Let me know how that goes

@amittleider
Copy link
Author

@DonJayamanne Thank you! Disabling Jedi fixes the issue.

@amittleider
Copy link
Author

Well, I notice after using the MS Python langauge server that it has its own problems. For example, sometimes I can't navigate with F12. Also, sometimes my VSCode gets stuck in a bad state and I have to reload. Also, it is not directly showing me symantec errors like a misspelled import. It puts a green squiggly underneath of it, but it's not obvious that it isn't simply a linting error like 'line length too long'.

I am assuming that the MS Python Language server will completely replace Jedi in the future? I hope the improvements come fast.

@DonJayamanne
Copy link

For example, sometimes I can't navigate with F12. Also, sometimes my VSCode gets stuck in a bad state and I have to reload. Also, it is not directly showing me symantec errors like a misspelled import. It puts a green squiggly underneath of it, but it's not obvious that it isn't simply a linting error like 'line length too long'.

Please create separate issues for each of these.

I am assuming that the MS Python Language server will completely replace Jedi in the future? I hope the improvements come fast.

Yes, that's correct. Again please create issues for these with examples so they can be looked at.

@rspeer
Copy link

rspeer commented Dec 11, 2018

The problem remains for me: the Python language server is insufficient at the moment, and I would rather keep using Jedi and disable the test code lens.

@DonJayamanne
Copy link

@rspeer

The problem remains for me: the Python language server is insufficient at the moment,

Please could you be more specific. I would like to understand the reasons better, as the plan is to migrate to the Language Server as the default.

@DonJayamanne
Copy link

@d3r3kk (on Windows) was able to replicate a similar issue. Basically code lenses do not appear for PyTest.
Use Flask repo.

@amittleider
Copy link
Author

Thanks for the update. I don't think it's related to just PyTest (I'm running with NoseTests). Also, I'm not sure what you mean by 'use flask repo'.

Indeed, Go To Definition hangs for me sometimes with MS language server, and I'm required to restart my VSCode, but this particular issue covers a code lens problem using Jedi.

@d3r3kk
Copy link

d3r3kk commented Dec 29, 2018

Use Flask repo.

Refers to reproduction - I was able to see your issue when I opened the Flask repo in VS Code with our extension.
Thanks for letting us know it isn't just PyTest.

@jonyrock
Copy link

Hey

I still can reproduce this issue on

This is my python config:

  "python.pythonPath": "python",
  "python.linting.enabled": true,
  "python.testing.unittestArgs": [ "-v" ],
  "python.testing.pyTestEnabled": false,
  "python.testing.nosetestsEnabled": false,
  "python.testing.unittestEnabled": true,
  "python.linting.pylintEnabled": true

Adding "python.jediEnabled": false fixes the behavior

@amittleider
Copy link
Author

@jonyrock , the original issue has not yet been resolved. However, I normally work around this issue by tabbing off and on the file again because IMO the MS Language Server is not nearly as good as Jedi for the moment.

@DonJayamanne
Copy link

because IMO the MS Language Server is not nearly as good as Jedi for the moment.

@amittleider Please could you create an issue with the details explaining why you believe Jedi is better.
We'd like to ensure we resolve all known issues to ensure the MS Language Server is better. FYI - The long term plan is to switch to MS LS as the default and leave Jedi as an opt in feature.

@amittleider
Copy link
Author

amittleider commented May 29, 2019

@DonJayamanne , the majority of issues with the MS Language Server for me are with the "Go to definition" and "Find references" functions. I have commented on an issue here: microsoft/python-language-server#850 .

Update: Here's a list of issues regarding the MS Language Server that prevent me from wanting to move away from Jedi:

@simonsabin
Copy link

FYI "python.jediEnabled":false worked for me also. The CodeLens adornments were disappearing. Switching Jedi off fixed the problem

kbd added a commit to kbd/setup that referenced this issue Nov 1, 2019
Attempting to get tests to stop 'jumping around' while writing code

microsoft/vscode-python#2790
@kbd
Copy link

kbd commented Nov 8, 2019

@DonJayamanne

We'd like to ensure we resolve all known issues to ensure the MS Language Server is better. FYI - The long term plan is to switch to MS LS as the default and leave Jedi as an opt in feature.

I switched to the Microsoft Python Language Server recently to get the "code lenses" for tests to stop constantly "jumping around" while writing code. Thankfully, it solved that problem, but now vscode can't find my library code and I get "unresolved import" warnings everywhere. This is documented, and I'm supposed to add a "python.autoComplete.extraPaths" setting (edit: or a .env file), but why should that be necessary when Jedi "just works"? If Python itself can find the imports, why shouldn't the Python Language Server also be able to, just as Jedi can?

@ghost
Copy link

ghost commented Sep 24, 2020

Bit of an old one, but I still see the "Run Test | Debug Test" buttons/links disappearing and re-appearing when saving the file if Jedi is used. This doesn't happen with the Microsoft language server.

OS: Windows_NT x64 10.0.19041
VSCode: 1.49.1
Python ext: v2020.9.111407

@amittleider
Copy link
Author

Bit of an old one, but I still see the "Run Test | Debug Test" buttons/links disappearing and re-appearing when saving the file if Jedi is used. This doesn't happen with the Microsoft language server.

OS: Windows_NT x64 10.0.19041
VSCode: 1.49.1
Python ext: v2020.9.111407

@vbersier From the discussions above, I don't think anyone plans on fixing the issue with Jedi either. Your best bet is to switch to the MS Language server, and if you find any issues using the MS language server, open issues for those, because you will be much better supported.

@kimadeline
Copy link

Fixed by #16769, we don't have code lenses anymore:

image

@kimadeline kimadeline added the verified Verification succeeded label Jul 29, 2021
@karthiknadig karthiknadig added this to the August 2021 milestone Aug 5, 2021
@github-actions github-actions bot locked as resolved and limited conversation to collaborators Sep 16, 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 verified Verification succeeded
Projects
None yet
Development

Successfully merging a pull request may close this issue.

10 participants