Repository navigation
pytest discovery fails with ModuleNotFound #24127
Copy link
Copy link
Closed
Labels
area-testinginfo-neededIssue requires more information from posterIssue requires more information from poster
Description
Type: Bug
Behaviour
pytest discovery fails with a ModuleNotFoundError, when the module is clearly installed in my environment
Steps to reproduce:
- Import non-standard package (but one that is installed in the environment) in
tests/conftest.py - Click on refresh tests
Diagnostic data
Output for Python in the Output panel (View→Output, 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 (a162831, 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.languageServersetting: 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
Reactions are currently unavailable
Metadata
Metadata
Labels
area-testinginfo-neededIssue requires more information from posterIssue requires more information from poster
Activity
eleanorjboyd commentedon 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 bealso go jackets (im a GT alum)
kjohnsen commentedon Sep 24, 2024
Hi Eleanor, thanks for getting back.
~/Dropbox (GaTech)is a symlink to~/GaTech Dropbox/Kyle Johnsen/$HOMEinstead of~) collected all the tests without a problemsys.path:sys.executableand 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!
eleanorjboyd commentedon Oct 1, 2024
Anthony Kim (@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!
Allow pytest to use correct interpreter from getActiveInterpreter (#2…
Allow pytest to use correct interpreter from getActiveInterpreter (#2…
Allow pytest to use correct interpreter from getActiveInterpreter (#2…
anthonykim1 commentedon Dec 3, 2024
With #24190 fixed can you test Kyle Johnsen (@kjohnsen) whether this issue persists?
anthonykim1 commentedon Dec 9, 2024
I think this shouldve been fixed with mentioned PRs, but please let us know if you are still suffering from this. Thanks
kjohnsen commentedon Dec 11, 2024
Yes, it's working now. Thank you.