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

pytest discovery fails with ModuleNotFound #24127

Open
kjohnsen opened this issue Sep 18, 2024 · 3 comments
Open

pytest discovery fails with ModuleNotFound #24127

kjohnsen opened this issue Sep 18, 2024 · 3 comments
Assignees
Labels
area-testing triage-needed Needs assignment to the proper sub-team

Comments

@kjohnsen
Copy link

Type: Bug

Behaviour

pytest discovery fails with a ModuleNotFoundError, when the module is clearly installed in my environment

Steps to reproduce:

  1. Import non-standard package (but one that is installed in the environment) in tests/conftest.py
  2. Click on refresh tests

Diagnostic data

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

2024-09-18 14:18:17.711 [info] > python -m pytest -p vscode_pytest --collect-only "--rootdir=~/Dropbox (GaTech)/projects/cleo"
2024-09-18 14:18:17.711 [info] cwd: ~/Dropbox (GaTech)/projects/cleo
2024-09-18 14:18:18.046 [info] Plugin info[vscode-pytest]: Checking if rootdir is a child of a symlink.
Checking for symlink parent starting at current path:  /home/kyle/Dropbox (GaTech)/projects/cleo
Symlink found at: /home/kyle/Dropbox (GaTech)
Plugin info[vscode-pytest]: rootdir argument, /home/kyle/Dropbox (GaTech)/projects/cleo, is identified as a symlink or child of a symlink, adjusting pytest paths accordingly.

2024-09-18 14:18:18.047 [error] ImportError while loading conftest '/home/kyle/GaTech Dropbox/Kyle Johnsen/projects/cleo/tests/conftest.py'.

2024-09-18 14:18:18.060 [error] tests/conftest.py:5: in <module>
    import brian2.only as b2
E   ModuleNotFoundError: No module named 'brian2'

2024-09-18 14:18:18.105 [error] Subprocess exited unsuccessfully with exit code 4 and signal null on workspace /home/kyle/Dropbox (GaTech)/projects/cleo.
2024-09-18 14:18:18.105 [error] Subprocess exited unsuccessfully with exit code 4 and signal null on workspace /home/kyle/Dropbox (GaTech)/projects/cleo. Creating and sending error discovery payload
2024-09-18 14:18:18.105 [error] pytest test discovery error for workspace:  /home/kyle/Dropbox (GaTech)/projects/cleo 
  
 The python test process was terminated before it could exit on its own, the process errored with: Code: 4, Signal: null for workspace /home/kyle/Dropbox (GaTech)/projects/cleo

Extension version: 2024.15.2024090406
VS Code version: Code - Insiders 1.94.0-insider (a162831c17ad0d675f1f0d5c3f374fd1514f04b5, 2024-09-06T12:53:19.832Z)
OS version: Windows_NT x64 10.0.22631
Modes:
Remote OS version: Linux x64 5.15.153.1-microsoft-standard-WSL2

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


languageServer: "Pylance"

testing
• pytestArgs: "<placeholder>"
• pytestEnabled: true
• autoTestDiscoverOnSaveEnabled: false

Installed Extensions
Extension Name Extension Id Version
autoDocstring - Python Docstring Generator njpwerner.autodocstring 0.6.1
C/C++ ms-vscode.cpptools 1.21.6
C/C++ Extension Pack ms-vscode.cpptools-extension-pack 1.3.0
CMake twxs.cmake 0.0.17
CMake Tools ms-vscode.cmake-tools 1.19.51
Code Spell Checker streetsidesoftware.code-spell-checker 3.0.1
Color Highlight naumovs.color-highlight 2.8.0
Even Better TOML tamasfe.even-better-toml 0.19.2
GitHub Copilot GitHub.copilot 1.229.1107
GitHub Copilot Chat GitHub.copilot-chat 0.21.2024091702
GitHub Pull Requests GitHub.vscode-pull-request-github 0.96.0
GitLens — Git supercharged eamodio.gitlens 2024.9.1705
HTML CSS Support ecmel.vscode-html-css 2.0.10
Insert Unicode brunnerh.insert-unicode 0.15.1
IntelliCode VisualStudioExptTeam.vscodeintellicode 1.3.1
IntelliCode API Usage Examples VisualStudioExptTeam.intellicode-api-usage-examples 0.2.8
JavaScript Debugger ms-vscode.js-debug 1.93.0
Jupyter ms-toolsai.jupyter 2024.9.2024091301
Jupyter Cell Tags ms-toolsai.vscode-jupyter-cell-tags 0.1.9
Jupyter Notebook Renderers ms-toolsai.jupyter-renderers 1.0.19
Jupyter Slide Show ms-toolsai.vscode-jupyter-slideshow 0.1.6
LaTeX Workshop James-Yu.latex-workshop 10.3.2
Live Preview ms-vscode.live-server 0.5.2024091601
Live Share ms-vsliveshare.vsliveshare 1.0.5940
Markdown Preview Enhanced shd101wyy.markdown-preview-enhanced 0.8.14
MATLAB MathWorks.language-matlab 1.2.5
MyST-Markdown ExecutableBookProject.myst-highlight 0.11.0
nbdev hamelhusain.nbdev 0.0.11
Path Intellisense christian-kohler.path-intellisense 2.9.0
Pylance ms-python.vscode-pylance 2024.9.1
Python ms-python.python 2024.14.1
Python Debugger ms-python.debugpy 2024.10.0
Quarto quarto.quarto 1.114.0
Rainbow CSV mechatroner.rainbow-csv 3.12.0
Ruff charliermarsh.ruff 2024.48.0
SVG jock.svg 1.5.4
Table Visualizer for JavaScript Profiles ms-vscode.vscode-js-profile-table 1.0.9
Tinymist Typst myriad-dreamin.tinymist 0.11.20
Typst LSP nvarner.typst-lsp 0.13.0
System Info
Item Value
CPUs Intel(R) Core(TM) i9-9980HK CPU @ 2.40GHz (16 x 2400)
GPU Status 2d_canvas: enabled
canvas_oop_rasterization: enabled_on
direct_rendering_display_compositor: disabled_off_ok
gpu_compositing: enabled
multiple_raster_threads: enabled_on
opengl: enabled_on
rasterization: enabled
raw_draw: disabled_off_ok
skia_graphite: disabled_off
video_decode: enabled
video_encode: enabled
vulkan: disabled_off
webgl: enabled
webgl2: enabled
webgpu: enabled
webnn: disabled_off
Load (avg) undefined
Memory (System) 31.73GB (8.73GB free)
Process Argv --crash-reporter-id 13862219-8062-4bb8-969d-b654fdb7b5e1
Screen Reader no
VM 0%
Item Value
Remote WSL: Ubuntu-22.04
OS Linux x64 5.15.153.1-microsoft-standard-WSL2
CPUs Intel(R) Core(TM) i9-9980HK CPU @ 2.40GHz (16 x 0)
Memory (System) 15.49GB (11.67GB free)
VM 0%
A/B Experiments
vsliv368:30146709
vspor879:30202332
vspor708:30202333
vspor363:30204092
vscod805cf:30301675
vsaa593cf:30376535
py29gd2263:31024238
c4g48928:30535728
962ge761:30841072
pythongtdpath:30726887
welcomedialog:30812478
pythonnoceb:30776497
asynctok:30898717
dsvsc014:30777825
dsvsc015:30821418
pythonmypyd1:30859725
h48ei257:31000450
pythontbext0:30879054
accentitlementst:30870582
dsvsc016:30879898
dsvsc017:30880771
dsvsc018:30880772
cppperfnew:30980852
pythonait:30973460
724cj586:31013169
a69g1124:31018687
dvdeprecation:31040973
dwnewjupytercf:31046870
nb_pkg_only:31057982
nativerepl1:31134653
refactort:31084545
pythonrstrctxt:31093868
flighttreat:31119334
wkspc-onlycs-t:31132770
nativeloc1:31118317
wkspc-ranged-t:31125599
3ad50483:31111987
jh802675:31132134
e80f6927:31120813
fje88620:31121564
notype1:31136707
b50ed353:31138333
showchatpanel:31139797
f8igb616:31140137

@github-actions github-actions bot added the triage-needed Needs assignment to the proper sub-team label Sep 18, 2024
@eleanorjboyd
Copy link
Member

eleanorjboyd commented Sep 23, 2024

Hi Kyle! Logs show there is a symlink and we do some path updating in that case to fix issues caused by the symlink we have seen in the past. To confirm is Symlink found at: /home/kyle/Dropbox (GaTech) a symlink? What does it map to if so? When you try this same thing from the command line is it found correct and everything? The equivalent command would be: python -m pytest --collect-only "--rootdir=~/Dropbox (GaTech)/projects/cleo" Finally if it works right from the command line, could you try printing the python path before the erroring import in your conftest.py file? Specifically looking to see if the rootdir is in it as expected or not. The code to do this would be

import sys
print(sys.path)

also go jackets (im a GT alum)

@github-actions github-actions bot added the info-needed Issue requires more information from poster label Sep 23, 2024
@kjohnsen
Copy link
Author

Hi Eleanor, thanks for getting back.

  • Yes, ~/Dropbox (GaTech) is a symlink to ~/GaTech Dropbox/Kyle Johnsen/
  • Running the command you gave me (though I had to use $HOME instead of ~) collected all the tests without a problem
  • rootdir looks like it was adjusted correctly. sys.path:
    • ['/home/kyle/GaTech Dropbox/Kyle Johnsen/projects/cleo/tests', '/home/kyle/GaTech Dropbox/Kyle Johnsen/projects/cleo', '/home/kyle/.vscode-server-insiders/extensions/ms-python.python-2024.14.1-linux-x64/python_files', '/home/kyle/miniforge3/lib/python312.zip', '/home/kyle/miniforge3/lib/python3.12', '/home/kyle/miniforge3/lib/python3.12/lib-dynload', '/home/kyle/miniforge3/lib/python3.12/site-packages', '/home/kyle/.vscode-server-insiders/extensions/ms-python.python-2024.14.1-linux-x64/python_files', '/home/kyle/.vscode-server-insiders/extensions/ms-python.python-2024.14.1-linux-x64/python_files/lib/python']
      
  • I printed sys.executable and it was indeed wrong—/home/kyle/miniforge3/bin/python—using my base conda environment instead of the selected interpreter for this workspace (~/miniforge3/envs/cleo/bin/python)

Go Jackets!

@github-actions github-actions bot removed the info-needed Issue requires more information from poster label Sep 24, 2024
@eleanorjboyd
Copy link
Member

@anthonykim1, looks like the issue here is the right environment is not being selected, this is likely related to the other issues we have seen with conda env activation. This investigation should help solve this issue as well: #24190. Thanks!

anthonykim1 added a commit that referenced this issue Oct 4, 2024
…4250)

Resolves: #24122
Related: #24190,
#24127

I think the culprit was we were not passing in interpreter when we call
createActivatedEnvironment.
karthiknadig pushed a commit that referenced this issue Oct 7, 2024
…4250)

Resolves: #24122
Related: #24190,
#24127

I think the culprit was we were not passing in interpreter when we call
createActivatedEnvironment.
karthiknadig pushed a commit that referenced this issue Oct 7, 2024
…4250)

Resolves: #24122
Related: #24190,
#24127

I think the culprit was we were not passing in interpreter when we call
createActivatedEnvironment.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area-testing triage-needed Needs assignment to the proper sub-team
Projects
None yet
Development

No branches or pull requests

3 participants