Skip to content

Fail to find pytest and collect tests in a conda environment #19070

Closed

Description

Issue Type: Bug

Behaviour

When opening a python test file or when clicking on the Testing button on the sidebar, all tests on the project should be listed. But now I am getting this error output:

> conda run -n my-work-env --no-capture-output --live-stream python ~\.vscode\extensions\ms-python.python-2022.4.1\pythonFiles\get_output_via_markers.py ~\.vscode\extensions\ms-python.python-2022.4.1\pythonFiles\testing_tools\run_adapter.py discover pytest -- --rootdir . -s --cache-clear --timeout=200 --color=yes --numprocesses=4 -ra ./source/python
cwd: .
[ERROR 2022-4-5 11:24:52.41]: Error discovering pytest tests:
 [r [Error]: Traceback (most recent call last):
  File "c:\Users\username\.vscode\extensions\ms-python.python-2022.4.1\pythonFiles\get_output_via_markers.py", line 26, in <module>
    runpy.run_path(module, run_name="__main__")
  File "W:\Miniconda\lib\runpy.py", line 263, in run_path
    pkg_name=pkg_name, script_name=fname)
  File "W:\Miniconda\lib\runpy.py", line 96, in _run_module_code
    mod_name, mod_spec, pkg_name, script_name)
  File "W:\Miniconda\lib\runpy.py", line 85, in _run_code
    exec(code, run_globals)
  File "c:\Users\username\.vscode\extensions\ms-python.python-2022.4.1\pythonFiles\testing_tools\run_adapter.py", line 17, in <module>
    from testing_tools.adapter.__main__ import parse_args, main
  File "c:\Users\username\.vscode\extensions\ms-python.python-2022.4.1\pythonFiles\testing_tools\adapter\__main__.py", line 9, in <module>
    from . import pytest, report
  File "c:\Users\username\.vscode\extensions\ms-python.python-2022.4.1\pythonFiles\testing_tools\adapter\pytest\__init__.py", line 7, in <module>
    from ._discovery import discover
  File "c:\Users\username\.vscode\extensions\ms-python.python-2022.4.1\pythonFiles\testing_tools\adapter\pytest\_discovery.py", line 8, in <module>
    import pytest
ModuleNotFoundError: No module named 'pytest'
ERROR conda.cli.main_run:execute(34): Subprocess for 'conda run ['python', 'c:\\Users\\username\\.vscode\\extensions\\ms-python.python-2022.4.1\\pythonFiles\\get_output_via_markers.py', 'c:\\Users\\username\\.vscode\\extensions\\ms-python.python-2022.4.1\\pythonFiles\\testing_tools\\run_adapter.py', 'discover', 'pytest', '--', '--rootdir', 'w:\\workspace-0\\Projects\\rocky\\rocky30coupling', '-s', '--cache-clear', '--timeout=200', '--color=yes', '--numprocesses=4', '-ra', 'w:\\Projects\\test/source/python']' command failed.  (See above for error)

	at ChildProcess.<anonymous> (c:\Users\username\.vscode\extensions\ms-python.python-2022.4.1\out\client\extension.js:32:38981)
	at Object.onceWrapper (node:events:510:26)
	at ChildProcess.emit (node:events:390:28)
	at maybeClose (node:internal/child_process:1064:16)
	at Process.ChildProcess._handle.onexit (node:internal/child_process:301:5)]

Expected vs. Actual

The expected behavior is to list the tests. It was working up to yesterday.

Steps to reproduce:

  1. Open a repository with the conda environment activated
  2. Click on the Testing button on the sidebar

Diagnostic data

  • Python version (& distribution if applicable, e.g. Anaconda): 3.6.11
  • Type of virtual environment used (e.g. conda, venv, virtualenv, etc.): Conda
  • Value of the python.languageServer setting: Pylance
User Settings


defaultLS: {"defaultLSType":"Pylance"}
downloadLanguageServer: true
languageServer: "Pylance"

linting
• enabled: true
• flake8Enabled: false
• lintOnSave: true
• banditEnabled: false
• mypyEnabled: false
• pycodestyleEnabled: false
• prospectorEnabled: false
• pydocstyleEnabled: false
• pylamaEnabled: false

formatting
• provider: "black"

testing
• debugPort: 3000
• nosetestsEnabled: undefined
• promptToConfigure: true
• pytestEnabled: true
• unittestEnabled: false
• autoTestDiscoverOnSaveEnabled: true

terminal
• activateEnvironment: true

experiments
• enabled: true
• optInto: []
• optOutFrom: []

tensorBoard

Extension version: 2022.4.1
VS Code version: Code 1.66.2 (dfd34e8260c270da74b5c2d86d61aee4b6d56977, 2022-04-11T07:46:01.075Z)
OS version: Windows_NT x64 10.0.19044
Restricted Mode: No

System Info
Item Value
CPUs Intel(R) Core(TM) i7-10700K CPU @ 3.80GHz (16 x 3792)
GPU Status 2d_canvas: enabled
canvas_oop_rasterization: disabled_off
direct_rendering_display_compositor: disabled_off_ok
gpu_compositing: enabled
multiple_raster_threads: enabled_on
oop_rasterization: enabled
opengl: enabled_on
rasterization: enabled
raw_draw: disabled_off_ok
skia_renderer: enabled_on
video_decode: enabled
video_encode: enabled
vulkan: disabled_off
webgl: enabled
webgl2: enabled
Load (avg) undefined
Memory (System) 31.93GB (25.71GB free)
Process Argv . --crash-reporter-id 3477419e-a590-4be7-b75c-2de539e04a42
Screen Reader no
VM 0%

Activity

  1. kimadeline commented on May 5, 2022

    @kimadeline

    Hi Joao Aguirre (@aguirre-esss), thank you for reaching out!

    Can you try opening your repo from a non-activated terminal, and see if the problem still occurs? There is an issue with conda run when running it from a terminal that already has an activated environment (conda/conda#11305, conda/conda#11174).

    Thanks!

  2. aguirre-esss commented on May 5, 2022

    @aguirre-esss
    Author

    Hello Kim-Adeline Miguel (@kimadeline), thank you for your attention.

    Indeed it works when launching VSCode from a shell without any environment activated. It seems to be the same issue that you have linked indeed.

    I am closing this issue as it it not a problem of the VSCode Python extension.

    Cheers! 👏

  3. locked as resolved and limited conversation to collaborators on Jun 5, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Labels

area-testingbugIssue identified by VS Code Team member as probable buginfo-neededIssue requires more information from postertriage-neededNeeds assignment to the proper sub-team

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions