Skip to content

Extension shows install pytest prompt when test discovery fails due to missing some another module #5730

@karthiknadig

Description

@karthiknadig

Environment data

  • VS Code version: 1.34.0
  • Extension version (available under the Extensions sidebar): 2019.6.16302-dev
  • OS and version: windows
  • Python version (& distribution if applicable, e.g. Anaconda): 3.7
  • Type of virtual environment used (N/A | venv | virtualenv | conda | ...): N/A
  • Relevant/affected Python packages and their versions: pytest

Expected behaviour

Should not show pytest install prompt, if pytest is installed. Insted say test discovery failed.
Bonus points if it can identify which module is actually missing ans show the right prompt.

Actual behaviour

image

Steps to reproduce:

  1. Use these settings:
{
    "python.pythonPath": "C:\\Python37\\python.exe",
    "python.testing.pyTestEnabled": true,
    "python.testing.nosetestsEnabled": false,
    "python.testing.unittestEnabled": false,
    "python.testing.pyTestArgs": [
        "."
    ],
}
  1. Add a file in root dir that imports some module that is not installed.
    pyqt_test.py:
from PyQt5.QtGui import *
from PyQt5.QtWidgets import *
from PyQt5.QtCore import *

# this is enough to get the prompt.

Logs

______________________ ERROR collecting pyqtapp_test.py _______________________
ImportError while importing test module 'c:\GIT\pyscratch2\pyqtapp_test.py'.
Hint: make sure your test modules/packages have valid Python names.
Traceback:
pyqtapp_test.py:1: in <module>
    from PyQt5.QtGui import *
E   ModuleNotFoundError: No module named 'PyQt5'
!!!!!!!!!!!!!!!!!!! Interrupted: 1 errors during collection !!!!!!!!!!!!!!!!!!!
=========================== 1 error in 0.10 seconds ===========================

Traceback (most recent call last):
  File "C:\Users\kanadig\.vscode\extensions\ms-python.python-2019.6.16302-dev\pythonFiles\testing_tools\run_adapter.py", line 16, in <module>
    main(tool, cmd, subargs, toolargs)
  File "C:\Users\kanadig\.vscode\extensions\ms-python.python-2019.6.16302-dev\pythonFiles\testing_tools\adapter\__main__.py", line 90, in main
    parents, result = run(toolargs, **subargs)
  File "C:\Users\kanadig\.vscode\extensions\ms-python.python-2019.6.16302-dev\pythonFiles\testing_tools\adapter\pytest\_discovery.py", line 35, in discover
    raise Exception('pytest discovery failed (exit code {})'.format(ec))
Exception: pytest discovery failed (exit code 2)

Metadata

Metadata

Assignees

No one assigned

    Labels

    area-testingbugIssue identified by VS Code Team member as probable bugverifiedVerification succeeded

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions