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

Cannot import any module from folder called "tests" using vscode #8840

Closed
xSupasx opened this issue Nov 28, 2019 · 9 comments
Closed

Cannot import any module from folder called "tests" using vscode #8840

xSupasx opened this issue Nov 28, 2019 · 9 comments
Assignees
Labels
bug Issue identified by VS Code Team member as probable bug info-needed Issue requires more information from poster

Comments

@xSupasx
Copy link

xSupasx commented Nov 28, 2019

Issue Type: Bug

when project has "tests" folder in the folder structure and there are modules that reside within it (python modules) then modules cannot be imported. If the name of the folder is changed everything works as expected.

VS Code version: Code 1.40.2 (f359dd69833dd8800b54d458f6d37ab7c78df520, 2019-11-25T14:54:45.096Z)
OS version: Windows_NT x64 10.0.18362

System Info
Item Value
CPUs Intel(R) Core(TM) i9-8950HK CPU @ 2.90GHz (12 x 2904)
GPU Status 2d_canvas: enabled
flash_3d: enabled
flash_stage3d: enabled
flash_stage3d_baseline: enabled
gpu_compositing: enabled
metal: disabled_off
multiple_raster_threads: enabled_on
oop_rasterization: disabled_off
protected_video_decode: enabled
rasterization: enabled
skia_renderer: disabled_off
surface_control: disabled_off
surface_synchronization: enabled_on
video_decode: enabled
viz_display_compositor: enabled_on
viz_hit_test_surface_layer: disabled_off
webgl: enabled
webgl2: enabled
Load (avg) undefined
Memory (System) 15.76GB (2.63GB free)
Process Argv
Screen Reader no
VM 0%
Extensions (38)
Extension Author (truncated) Version
Bookmarks ale 10.6.0
cucumberautocomplete ale 2.14.1
scratchpads bue 0.0.7
npm-intellisense chr 1.3.0
path-intellisense chr 1.4.2
vscode-eslint dba 1.9.1
gitlens eam 10.2.0
vscode-npm-script eg2 0.3.9
json-tools eri 1.0.2
code-runner for 0.9.15
gc-excelviewer Gra 2.1.32
path-autocomplete ion 1.13.3
search-node-modules jas 1.3.0
vscode-codemetrics kis 1.23.0
node-module-intellisense lei 1.5.0
codeacejumper luc 2.1.7
MagicPython mag 1.1.0
dotenv mik 1.0.1
vscode-azurefunctions ms- 0.20.0
python ms- 2019.11.50794
remote-wsl ms- 0.40.3
azure-account ms- 0.8.7
csharp ms- 1.21.8
mono-debug ms- 0.15.8
powershell ms- 2019.11.0
vsliveshare ms- 1.0.1293
vsliveshare-audio ms- 0.1.80
debugger-for-chrome msj 4.12.1
autodocstring njp 0.4.0
vscode-for-node-js-development-pack nod 2.0.1
vscode-jest Ort 3.0.2
code-settings-sync Sha 3.4.3
ayu tea 0.18.0
snippet-creator vin 1.1.0
vscodeintellicode Vis 1.2.0
nodejs-extension-pack wad 0.1.9
vscode-import-cost wix 2.12.0
JavaScriptSnippets xab 1.7.2
I've discovered that it is a problem with this in particular: C:\Users\aslupek\AppData\Local\Programs\Python\Python37-32\lib\site-packages\tests\init.py - this is what gets assigned when I debug importing only "tests" module. My python version is: 3.7.4
@xSupasx xSupasx added triage-needed Needs assignment to the proper sub-team bug Issue identified by VS Code Team member as probable bug labels Nov 28, 2019
@brettcannon
Copy link
Member

This means your sys.path is being set such that the stdlib's tests package is shadowing yours. Are you manipulating your PYTHONPATH or sys.path in any way, and if so how? Have you printed out sys.path to see what it is set to?

@brettcannon brettcannon added the info-needed Issue requires more information from poster label Nov 29, 2019
@xSupasx
Copy link
Author

xSupasx commented Dec 2, 2019

I'm not manipulating the sys.path but you're right the url for site-packages is shadowing my repo. I can switch the order of it but does it really solve the issue? In pycharm it works perfectly fine for the same project. Only wondering :)

@brettcannon
Copy link
Member

It might have to do with how pytest sets things up based on how we invoke it (we don't manipulate sys.path for you). Can you look in the Output Panel and see how we invoke pytest on your behalf and see if you get the same results when you run it manually the exact same way from the terminal? My guess it's a difference between pytest and python -m pytest that's subtly different here.

@ghost ghost removed the triage-needed Needs assignment to the proper sub-team label Dec 2, 2019
@xSupasx
Copy link
Author

xSupasx commented Dec 3, 2019

well when invoking pytest there is no difference really. The problem is when I want to use a script that is not a test. Then the import doesn't work - I found a workaround using the PYTHONPATH in the .evn file in the project but still would expect to work as it does in different tools:)

@kimadeline
Copy link

Hi @xSupasx 👋 Could you provide a sample project and steps to reproduce your issue so that we can take a look?

Thanks :)

@brettcannon
Copy link
Member

@xSupasx please provide a reproducer as @kimadeline requested, but if this is due to running code as a script then it will most likely be due to the directory you're executing from (i.e. PyCharm may be changing your current working directory for you implicitly while we are not unless you ask us to).

@xSupasx
Copy link
Author

xSupasx commented Dec 5, 2019

I will, don't have the possibility now. Will provide the structure later today.

@xSupasx
Copy link
Author

xSupasx commented Dec 6, 2019

During the creation of a repo to reproduce the bug I found actually another thing. During running the file the PYTHONPATH simply isn't enriched with the workspace folder hence the imports fail. Is the only solution for this adding the .env file with pythonpath modification within it? Maybe as an addition to the current file location that is bein ran (this path is added) would be good to also add the workspace folder(it is like this in pycharm i.e) if this is some known issue/feature then please close the bug.

@brettcannon
Copy link
Member

@xSupasx we don't touch your PYTHONPATH for you, so this not surprising. When we execute Python it is from the workspace, although if you're working from a multi-root workspace that changes things as it's relative to each workspace.

So it seems like your folder structure is such you need to specify PYTHONPATH, so I will close this as solved.

@ghost ghost removed the triage label Dec 6, 2019
@lock lock bot locked as resolved and limited conversation to collaborators Dec 13, 2019
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
bug Issue identified by VS Code Team member as probable bug info-needed Issue requires more information from poster
Projects
None yet
Development

No branches or pull requests

4 participants