microsoft / vscode-python

Python extension for Visual Studio Code
https://aka.ms/pvsc-marketplace
MIT License
4.31k stars 1.18k forks source link

Unittest error link not parsing line number #7196

Closed memeplex closed 3 years ago

memeplex commented 5 years ago

Environment data

Expected behaviour

After running a failing test, a Python Test Log output like:

  File "/home/carlos/Projects/Jampp/Gcd/tests/gcd/test_cache.py", line 44, in test
    self.assertEqual(cache['a'], 12)
AssertionError: 1 != 12

should send me to line 44 in test_cache.py after clicking on the link.

Actual behaviour

It only opens test_cache.py at current line, not even scrolling to make line 44 visible.

Parsing line number in error output is a basic functionality I've seen implemented in any major editor I've used before (vim, emacs).

Steps to reproduce:

  1. Set unittest as your testing framework.
  2. Write a failing test
  3. Run the test
  4. Put the cursor at the beginning of the test file.
  5. Open another file.
  6. In the Test log click the link to the test file.
  7. The cursor will be still at the beginning of the file.

Logs

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

User belongs to experiment group 'ShowExtensionSurveyPrompt - control'
> conda --version
> pyenv root
> python3.7 -c "import sys;print(sys.executable)"
> python3.6 -c "import sys;print(sys.executable)"
> python3 -c "import sys;print(sys.executable)"
> python2 -c "import sys;print(sys.executable)"
> python -c "import sys;print(sys.executable)"
> python -c "import sys;print(sys.executable)"
> conda info --json
Starting Jedi Python language engine.
> /usr/bin/python3 -c "
import unittest
loader = unittest.TestLoader()
suites = loader.discover(".", pattern="test_*.py")
print("start") #Don't remove this line
for suite in suites._tests:
    for cls in suite._tests:
        try:
            for m in cls._tests:
                print(m.id())
        except:
            pass"
cwd: ~/Projects/Jampp/Gcd
> /usr/bin/python3 -c "
import unittest
loader = unittest.TestLoader()
suites = loader.discover(".", pattern="test_*.py")
print("start") #Don't remove this line
for suite in suites._tests:
    for cls in suite._tests:
        try:
            for m in cls._tests:
                print(m.id())
        except:
            pass"
cwd: ~/Projects/Jampp/Gcd
> conda info --json
> conda --version
> /usr/bin/python3 -c "import sys;print(sys.prefix)"
cwd: ~/Projects/Jampp/Gcd
> /usr/bin/python3 -c "import sys;print(sys.prefix)"
cwd: ~/Projects/Jampp/Gcd
> /usr/bin/python3 -c "import sys;print(sys.executable)"
cwd: ~/Projects/Jampp/Gcd
> /usr/bin/python3 -c "import sys;print(sys.executable)"
cwd: ~/Projects/Jampp/Gcd
> /usr/bin/python3 -c "from distutils.sysconfig import get_python_lib; print(get_python_lib())"
cwd: ~/Projects/Jampp/Gcd
> /usr/bin/python3 -c "from distutils.sysconfig import get_python_lib; print(get_python_lib())"
cwd: ~/Projects/Jampp/Gcd
> /usr/bin/python3 -m site --user-site
cwd: ~/Projects/Jampp/Gcd
> /usr/bin/python3 -m site --user-site
cwd: ~/Projects/Jampp/Gcd
> /usr/bin/python3 -m flake8 --ignore=E306,W504 --format=%(row)d,%(col)d,%(code).1s,%(code)s:%(text)s ~/Projects/Jampp/Gcd/tests/gcd/test_cache.py
cwd: ~/Projects/Jampp/Gcd
> /usr/bin/python3 -m flake8 --ignore=E306,W504 --format=%(row)d,%(col)d,%(code).1s,%(code)s:%(text)s ~/Projects/Jampp/Gcd/tests/gcd/test_cache.py
cwd: ~/Projects/Jampp/Gcd
> /usr/bin/python3 completion.py
cwd: ~/.vscode/extensions/ms-python.python-2019.9.34474/pythonFiles
> /usr/bin/python3 completion.py
cwd: ~/.vscode/extensions/ms-python.python-2019.9.34474/pythonFiles
##########Linting Output - flake8##########
> /usr/bin/python3 -m flake8 --ignore=E306,W504 --format=%(row)d,%(col)d,%(code).1s,%(code)s:%(text)s ~/Projects/Jampp/Daat/tests/daat/test_model.py
cwd: ~/Projects/Jampp/Daat/tests/daat
> /usr/bin/python3 -m flake8 --ignore=E306,W504 --format=%(row)d,%(col)d,%(code).1s,%(code)s:%(text)s ~/Projects/Jampp/Daat/tests/daat/test_model.py
cwd: ~/Projects/Jampp/Daat/tests/daat
##########Linting Output - flake8##########
> /usr/bin/python3 ~/.vscode/extensions/ms-python.python-2019.9.34474/pythonFiles/visualstudio_py_testlauncher.py --us=. --up=test_*.py --uvInt=2 --result-port=33007 -ttests.gcd.test_cache.TestCache.test --testFile=/home/carlos/Projects/Jampp/Gcd/tests/gcd/test_cache.py
cwd: ~/Projects/Jampp/Gcd
> /usr/bin/python3 ~/.vscode/extensions/ms-python.python-2019.9.34474/pythonFiles/visualstudio_py_testlauncher.py --us=. --up=test_*.py --uvInt=2 --result-port=33007 -ttests.gcd.test_cache.TestCache.test --testFile=/home/carlos/Projects/Jampp/Gcd/tests/gcd/test_cache.py
cwd: ~/Projects/Jampp/Gcd
> /usr/bin/python3 ~/.vscode/extensions/ms-python.python-2019.9.34474/pythonFiles/visualstudio_py_testlauncher.py --us=. --up=test_*.py --uvInt=2 --result-port=45119
cwd: ~/Projects/Jampp/Gcd
> /usr/bin/python3 ~/.vscode/extensions/ms-python.python-2019.9.34474/pythonFiles/visualstudio_py_testlauncher.py --us=. --up=test_*.py --uvInt=2 --result-port=45119
cwd: ~/Projects/Jampp/Gcd
> /usr/bin/python3 -m flake8 --ignore=E306,W504 --format=%(row)d,%(col)d,%(code).1s,%(code)s:%(text)s ~/Projects/Jampp/Gcd/tests/gcd/test_cache.py
cwd: ~/Projects/Jampp/Gcd
> /usr/bin/python3 -m flake8 --ignore=E306,W504 --format=%(row)d,%(col)d,%(code).1s,%(code)s:%(text)s ~/Projects/Jampp/Gcd/tests/gcd/test_cache.py
cwd: ~/Projects/Jampp/Gcd
##########Linting Output - flake8##########
> /usr/bin/python3 -c "
import unittest
loader = unittest.TestLoader()
suites = loader.discover(".", pattern="test_*.py")
print("start") #Don't remove this line
for suite in suites._tests:
    for cls in suite._tests:
        try:
            for m in cls._tests:
                print(m.id())
        except:
            pass"
cwd: ~/Projects/Jampp/Gcd
> /usr/bin/python3 -c "
import unittest
loader = unittest.TestLoader()
suites = loader.discover(".", pattern="test_*.py")
print("start") #Don't remove this line
for suite in suites._tests:
    for cls in suite._tests:
        try:
            for m in cls._tests:
                print(m.id())
        except:
            pass"
cwd: ~/Projects/Jampp/Gcd
> /usr/bin/python3 ~/.vscode/extensions/ms-python.python-2019.9.34474/pythonFiles/visualstudio_py_testlauncher.py --us=. --up=test_*.py --uvInt=2 --result-port=33919 -ttests.gcd.test_cache.TestCache --testFile=/home/carlos/Projects/Jampp/Gcd/tests/gcd/test_cache.py
cwd: ~/Projects/Jampp/Gcd
> /usr/bin/python3 ~/.vscode/extensions/ms-python.python-2019.9.34474/pythonFiles/visualstudio_py_testlauncher.py --us=. --up=test_*.py --uvInt=2 --result-port=33919 -ttests.gcd.test_cache.TestCache --testFile=/home/carlos/Projects/Jampp/Gcd/tests/gcd/test_cache.py
cwd: ~/Projects/Jampp/Gcd
kimadeline commented 5 years ago

Hello @memeplex, thank you for reaching out πŸ‘‹ Does this problem happen if you use Jedi instead of the Language Server?

memeplex commented 5 years ago

Yes, it's the same with Jedi and with MLS (I've updated the description to inform about this).

I'm not sure how that is related to the issue, though. Is unit test output being processed by the language server?

kimadeline commented 5 years ago

Sorry about that, read too fast and thought it had something to do with intellisense 😬

memeplex commented 5 years ago

Ok, no problem, do you need more info from me? (because of the info needed label)

kimadeline commented 5 years ago

Not at the moment, I will investigate the issue and get back to you (and re-add the label) if necessary.

Thanks!

kimadeline commented 5 years ago

Can reproduce it πŸ” Since this is more of an enhancement, this will be marked as "needs decision" to make sure we have a conversation about it. We plan to leave this feature request open for at least a month to see how many πŸ‘ votes your idea gets to help us make our decision.

brettcannon commented 3 years ago

We are moving over to a new test provider which should make needing to look at the Python test log unnecessary (at least most of the time). As well, VS Code controls the linking in the Output panel, so this would be an ask over there.