Skip to content

"Compilation" error does not report tests in test tree #15204

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
zackarydev opened this issue Jan 22, 2021 · 3 comments
Closed

"Compilation" error does not report tests in test tree #15204

zackarydev opened this issue Jan 22, 2021 · 3 comments
Labels
area-testing feature-request Request for new features or functionality

Comments

@zackarydev
Copy link

zackarydev commented Jan 22, 2021

Environment data

  • VS Code version: 1.52.1
  • Extension version (available under the Extensions sidebar): 2021.1.502429796
  • OS and version: Darwin x64 20.3.0
  • Python version (& distribution if applicable, e.g. Anaconda): 3.6
  • Type of virtual environment used (N/A | venv | virtualenv | conda | ...): venv
  • Relevant/affected Python-related VS Code extensions and their versions: Pylance (2021.1.2)
  • Value of the python.languageServer setting: Pylance

Expected behaviour

When a test cannot be imported due to code failures (ex: invalid syntax, import errors) I expect the test to be reported in the test view. Its super important to make these errors visible... There are a bunch of tests that contain error and just failed
"silently".

Actual behaviour

The test fails silently and the test is not reported in the test treeview. (it is reported in the Python Test Log under output though)

Steps to reproduce:

Create a file:

# tests/helpers.py
def get_constants_from_class(class): # <-- invalid syntax here 'class' is a reserved keyword!
    # https://stackoverflow.com/questions/1398022/looping-over-all-member-variables-of-a-class-in-python
    get_consts = lambda x: [attr for attr in dir(x) if not callable(getattr(x, attr)) and not attr.startswith("__")]
    return get_consts(class)

Create a test that imports this function:

# tests/unit_tests/test_has_all_constants.py
import unittest

from tests.helpers import get_constants_from_class

Class TestHasAllConstants(unittest.TestCase):
    def test_has_a_const(self):
           get_constants_from_class(SomeClass)

Run tests using the test view:

Screen Shot 2021-01-22 at 3 34 53 PM

Notice that the class is not identified.

Look at the Python logs:

======================================================================
ERROR: some.module (unittest.loader._FailedTest)
----------------------------------------------------------------------
ImportError: Failed to import test module: some.module
Traceback (most recent call last):
  File "/opt/python3.6/lib/python3.6/unittest/loader.py", line 428, in _find_test_path
    module = self._get_module_from_name(name)
  File "/opt/python3.6/lib/python3.6/unittest/loader.py", line 369, in _get_module_from_name
    __import__(name)
  File "/some/file.path.py", line 4, in <module>
    from tests.helpers import get_constants_from_class
  File "/home/vmagent/app/tests/helpers.py", line 17
    def get_constants_from_class(class: Any):
                                     ^
SyntaxError: invalid syntax

Logs

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

======================================================================
ERROR: some.module (unittest.loader._FailedTest)
----------------------------------------------------------------------
ImportError: Failed to import test module: some.module
Traceback (most recent call last):
  File "/opt/python3.6/lib/python3.6/unittest/loader.py", line 428, in _find_test_path
    module = self._get_module_from_name(name)
  File "/opt/python3.6/lib/python3.6/unittest/loader.py", line 369, in _get_module_from_name
    __import__(name)
  File "/some/file.path.py", line 4, in <module>
    from tests.helpers import get_constants_from_class
  File "/home/vmagent/app/tests/helpers.py", line 17
    def get_constants_from_class(class: Any):
                                     ^
SyntaxError: invalid syntax

@zackarydev zackarydev added triage-needed Needs assignment to the proper sub-team bug Issue identified by VS Code Team member as probable bug labels Jan 22, 2021
@zackarydev
Copy link
Author

This might? be related: #15147

@karthiknadig karthiknadig added needs decision feature-request Request for new features or functionality and removed bug Issue identified by VS Code Team member as probable bug labels Jan 25, 2021
@ghost ghost removed the triage-needed Needs assignment to the proper sub-team label Jan 25, 2021
@karthiknadig
Copy link
Member

The PR will partially address this #15129. To actually report this in the test tree, that is a new feature. We have marked this issue as "needs decision" to make sure we have a conversation about your idea. We plan to leave this feature request open for at least a month to see how many 👍 votes the opening comment gets to help us make our decision.

@github-actions github-actions bot removed the needs PR label Aug 9, 2022
@karrtikr karrtikr added the needs PR Ready to be worked on label Aug 9, 2022
@eleanorjboyd
Copy link
Member

Hello! Just fixed this in our new python rewrite. Error tolerant discovery is now out on insiders and will go out on stable in the next release. It is part of our testing rewrite and so if you would like to try it yourself, you need to add this setting to your users settings.json "python.experiments.optInto": ["pythonTestAdapter"] on insiders. Let me know if it doesn’t work for you and we can re-open this issue. Thanks!

@github-actions github-actions bot removed the needs PR Ready to be worked on label Jul 14, 2023
@github-actions github-actions bot locked as resolved and limited conversation to collaborators Aug 14, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
area-testing feature-request Request for new features or functionality
Projects
None yet
Development

No branches or pull requests

5 participants