question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

pytest broken (run fails on module discovery, debug works)

See original GitHub issue

Issue Type: Bug With the latest Python extension update (2020.10.332292344), pytests are unable to run tests, while I can debug them normally. This happens only when pytests are run via VS Code. If run via cmd, this is is not the case. Works on previous version: v2020.9.114305.

I discovered that new plugin has different sys.path list. Debug (working):

sys.path:
    w:\AsystLib\isys\python
    W:\APPS\PythonModules
    ...

While run (failing):

sys.path:
    c:\Users\domen\.vscode\extensions\ms-python.python-2020.10.332292344\pythonFiles
    W:\APPS\PythonModules

As you can see, first enty: w:\AsystLib\isys\python is missing and is replaced with VSC extension path. Error:

=================================== ERRORS ====================================
___________________ ERROR collecting isys_tests/test_svn.py ___________________
ImportError while importing test module 'w:\AsystLib\isys\python\isys_tests\test_svn.py'.
Hint: make sure your test modules/packages have valid Python names.
Traceback:
isys_tests\test_svn.py:13: in <module>
    import isys.generic
E   ModuleNotFoundError: No module named 'isys'
- generated xml file: C:\Users\domen\AppData\Local\Temp\tmp-22572SU2jr85kY5KB.xml -
=========================== short test summary info ===========================
ERROR isys_tests/test_svn.py
============================== 1 error in 0.03s ===============================
ERROR: not found: w:\AsystLib\isys\python\isys_tests\test_svn.py::test_getStatus
(no name 'w:\\AsystLib\\isys\\python\\isys_tests\\test_svn.py::test_getStatus' in any of [<Module isys_tests/test_svn.py>])

isys is a folder inside: w:\AsystLib\isys\python where many modules are placed, for example isys.generic. Module is accessible in standard run/debug launch configuratoin, but not in pytest run mode.

I couldn’t reproduce this with the most simple single-folder VSC workspace. My workspace merge a couple of folders, some with and some without VSC wks/settings files. There are errors in other workspace folders, but this does not explain this scenario, where debug works while run doesn’t.

Let me know how can I help since this is again, major drawback in workflow.

Extension version: 2020.10.332292344 VS Code version: Code 1.50.1 (d2e414d9e4239a252d1ab117bd7067f125afd80a, 2020-10-13T15:06:15.712Z) OS version: Windows_NT x64 10.0.18363

System Info
Item Value
CPUs Intel® Core™ i7-6820HQ CPU @ 2.70GHz (8 x 2712)
GPU Status 2d_canvas: enabled
flash_3d: enabled
flash_stage3d: enabled
flash_stage3d_baseline: enabled
gpu_compositing: enabled
multiple_raster_threads: enabled_on
oop_rasterization: disabled_off
opengl: enabled_on
protected_video_decode: unavailable_off
rasterization: enabled
skia_renderer: disabled_off_ok
video_decode: enabled
vulkan: disabled_off
webgl: enabled
webgl2: enabled
Load (avg) undefined
Memory (System) 15.92GB (6.63GB free)
Process Argv W:\AsystLib\isys\python\VSCodeDevWorkspace_refactor.code-workspace --crash-reporter-id 919e0ed9-46f3-4ad4-9e28-f35755bf8266
Screen Reader no
VM 0%

Issue Analytics

  • State:closed
  • Created 3 years ago
  • Reactions:16
  • Comments:13

github_iconTop GitHub Comments

7reactions
CanntAimcommented, Nov 12, 2020

Adding an __init__.py in the test suite folder also seemed to “fix” this particular issue for me without requiring a downgrade. You really shouldn’t need it there for the test suite to work though thus the cautious use of the word fix.

4reactions
karrtikrcommented, Nov 25, 2020

Thanks all for the info! Should be fixed as part of https://github.com/microsoft/vscode-python/issues/14570 which is planned for the next release.

Read more comments on GitHub >

github_iconTop Results From Across the Web

VSCode pytest test discovery fails - python - Stack Overflow
As a noob, I was putting my unit tests inside the module files, since I was following the pattern of unittest , and...
Read more >
How to handle test failures — pytest documentation
This will invoke the Python debugger on every failure (or KeyboardInterrupt). Often you might only want to do this for the first failing...
Read more >
Writing and running tests - Django documentation
Django's unit tests use a Python standard library module: unittest . This module defines tests using a class-based approach.
Read more >
Python Debugging With Pdb
You can also break into the debugger, without modifying the source and using pdb.set_trace() or breakpoint() , by running Python directly from the ......
Read more >
Python and Flask Tutorial in Visual Studio Code
Python Flask tutorial showing IntelliSense, debugging, and code ... If you see an error that the Flask module cannot be found, make sure...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found