Description
Type: Bug
Behaviour
NOTE: not sure if it's a bug report or feature request to solve a bug
Hi! I am JD from the developer experience team at Rippling, and we are exploring moving the company's official editor from Pycharm to VSCode, but we are running on some critical issues when trying to use the test runner/debugger feature.
For at least the pytest runs, test discovery currently functions by running pytest with the --collect-only flag to gather data about all current tests. For reasonable codebases, this works quite well, reasonably quick, and is a clever way of not re-inventing the wheel with test discovery.
For large codebases with ~60K tests and ~300 dependencies, this becomes a problem. In our ci with larger machines, pytest --collect-only takes a little over 3 minutes to run, and ~10 minutes in the developer VMs we tested this out on. During this time, the editor's child process also consume updwards of 16GB of RAM. Moreover, afterwards the test line placement was wrong and the editor begins to show a myriad of ui errors, to the point of just restarting it from the frustration.
It is not a big leap of imagination to consider that the issue comes from the fact that we're trying to collect an insane number of tests in one go. We understand why this default strategy was chosen, but are hard-pressed to find alternatives.
One solution which we've poc'd following this guide was to not rely on pytest for the test discovery, but rather do a primitive syntax scan on the currently open python files and dynamically identify the tests following the simple innate rules:
- Does the file fit the regex “test_*.py”?
- Does the class start with “Test”?
- Does the function start with “test”?
We found that this discovery strategy is quite snappy, takes up pretty much no resources, and works for almost all test cases (unless you're doing something really advanced with pytest/conftest).
Our ask is:
- Is there such a feature already available that we missed?
- If there isn't, is there something on the short-term road map for this?
- If there isn't, is can you help us out in making a PR to add this as an optional discovery strategy? (like point us to what part of the code needs to be updated for this to function-- I think it is pythonFiles/tests/testing_tools/adapter/pytest/test_discovery.py or pythonFiles/tests/pytestadapter/test_discovery.py or src/client/testing/testController/pytest/pytestDiscoveryAdapter.ts but I am not sure)
Expected vs. Actual
For the currently open test files, Pytest discovery
- Works quickly (10 seconds)
- Works correctly
- Does not consume ~16GB of ram
Actual: freezes for 10 minutes and then breaks
Steps to reproduce:
- Get a codebase with ~60K tests and ~300 dependencies.
- Setup the venv everything usual there.
- Do the regular flow to configure test runner with pytest.
- Watch as your editor stalls for 10 minutes and then enters a broken state.
Diagnostic data
- Python version (& distribution if applicable, e.g. Anaconda): 3.10.11
- Type of virtual environment used (e.g. conda, venv, virtualenv, etc.): Poetry
- Value of the
python.languageServer
setting: Default
Output for Python
in the Output
panel (View
→Output
, change the drop-down the upper-right of the Output
panel to Python
)
XXX
User Settings
languageServer: "Pylance"
testing
• pytestArgs: "<placeholder>"
• pytestEnabled: true
Extension version: 2023.14.0
VS Code version: Code 1.81.1 (Universal) (6c3e3dba23e8fadc360aed75ce363ba185c49794, 2023-08-09T22:20:33.924Z)
OS version: Darwin arm64 22.6.0
Modes:
System Info
Item | Value |
---|---|
CPUs | Apple M1 Pro (10 x 24) |
GPU Status | 2d_canvas: enabled canvas_oop_rasterization: disabled_off direct_rendering_display_compositor: disabled_off_ok gpu_compositing: enabled metal: disabled_off multiple_raster_threads: enabled_on opengl: enabled_on rasterization: enabled raw_draw: disabled_off_ok video_decode: enabled video_encode: enabled vulkan: disabled_off webgl: enabled webgl2: enabled webgpu: enabled |
Load (avg) | 5, 5, 5 |
Memory (System) | 32.00GB (0.32GB free) |
Process Argv | . --crash-reporter-id 93d076a8-2779-4634-a060-d784b251ef33 |
Screen Reader | no |
VM | 0% |
A/B Experiments
vsliv368cf:30146710
vsreu685:30147344
python383:30185418
vspor879:30202332
vspor708:30202333
vspor363:30204092
vswsl492cf:30256860
vslsvsres303:30308271
vserr242:30382549
pythontb:30283811
vsjup518:30340749
pythonptprofiler:30281270
vsdfh931:30280409
vshan820:30294714
vstes263cf:30335440
vscoreces:30445986
vscod805cf:30301675
binariesv615:30325510
bridge0708:30335490
bridge0723:30353136
vsaa593:30376534
pythonvs932:30410667
vsclangdf:30486550
c4g48928:30535728
dsvsc012:30540252
pynewext54:30695312
azure-dev_surveyone:30548225
vscccc:30803845
2e4cg342:30602488
f6dab269:30613381
a9j8j154:30646983
showlangstatbar:30737416
03d35959:30757346
pythonfmttext:30731395
fixshowwlkth:30771522
showindicator:30805244
pythongtdpath:30769146
i26e3531:30792625
pythonnosmt12:30797651
pythonidxpt:30805730
pythonnoceb:30805159
dsvsc013:30795093
dsvsc014:30804076
diffeditorv2:30821572