pytest fails module not found, even tho tests are discovered & works in debug,
See original GitHub issueThank you for your help! I have search many issues, and tried many solutions, but I can’t figure it out. I understand this is OSS, and no one may have time or interest to help me. That’s okay. I am very grateful for vscode-python, and appreciate your time.
We have written the needed data into your cl
- VS Code Version: 1.53.2
- OS Version: Windows 10.0.17763
- Python: 3.6.9 from python.org, running in venv
- pytest 6.2.2
Version: 1.53.2 (user setup) Commit: 622cb03f7e070a9670c94bae1a45d78d7181fbd4 Date: 2021-02-11T11:48:04.245Z Electron: 11.2.1 Chrome: 87.0.4280.141 Node.js: 12.18.3 V8: 8.7.220.31-electron.0 OS: Windows_NT x64 10.0.17763
Steps to Reproduce:
- use python 3.6 to create a virtualenv:
$py -3.6 -m venv venv
- install requirements for pvlib and install pvlib in editable mode:
pip install --no-deps -e .
- open pvlib folder in vscode, it chooses venv automatically, yay!
- see test are all discovered
- try to run tests, select pytest as test runner, use default
setup.cfg
as only setting - pick any test and run it, but it fails to import pvlib in
conftest.py
ImportError while loading conftest 'c:\Users\mikm\Projects\pvlib-python\pvlib\tests\conftest.py'.
pvlib\tests\conftest.py:10: in <module>
import pvlib
E ModuleNotFoundError: No module named 'pvlib'
Error: TypeError: Cannot read property 'testsuites' of null
- run the same test again using debug, and it works!
- try it in the console or a windows CMD, and it works!
(venv) $ pytest pvlib/tests/test_infinite_sheds.py::test_gcr_prime
Does this issue occur when all extensions are disabled?: Yes/No
If I disable extensions, then the Python extension isn’t loaded, and so no tests are discovered, and so I can’t run them.
I have the following extensions installed and enabled: Python, Remote-WSL, Jupyter, Git History, C#, and C/C++
If I disable everything but Python and Jupyter (I cannot disable only Jupyter), the tests are still discovered, but still do not run.
Related Issues
Issue Analytics
- State:
- Created 3 years ago
- Reactions:1
- Comments:12 (1 by maintainers)
Top GitHub Comments
@mikofski I see the same behavior on my mac in my conda environment and having installed pvlib using
pip install -e .
. It’s been awhile since I’ve used vscode in this way so I didn’t notice when it broke (for no particular reason I am in the habit of using vscode’s debug test or running from the command line). I’ll guess it worked about 3 months ago. Sorry I didn’t actually try this when you first reported the issue - I initially understood it to be limited tovirtualenv
.I would like to add that this also solved my bug. This being that pytest or in other words testing does not respect PYTHONPATH when it is in the root directory.
The fix, that is, adding “python.useIsolation”: false` to Preferences: Open Settings (JSON) solved the following issue:
add the parent directory that foo and test reside in to your PYTHONPATH (with Mac this is done through sudo nano /private/etc/zprofile and then add :
export PYTHONPATH=~/folder/to/example_parent
open vscode
within vscode open example_parent
press ctrl+shift+p and then type python all tests
enable and configure pytest in the root directory
run pytest within vscode through the python run all tests setting with vscode opened in root
You will receive the following error