vscode-python: Pytest Discovery does nothing when python.testing.cwd is set

Type: Bug

Behaviour

Expected vs. Actual

Expect pytest discovery can found tests. And if not - reports what is wrong.

Steps to reproduce:

  1. create workspace-folder | create workspace with folder (I checked both, thinking of #21082 #22218)

  2. inside any folder create pytest_issue

  3. inside pytest_issue/test_foo.py with any test, e.g. def test_foo(): .... image

  4. ensure config for workspace or folder:

    "python.testing.cwd": "pytest_issue",
    "python.testing.pytestArgs": [],
    "python.testing.unittestEnabled": false,
    "python.testing.pytestEnabled": true,
  1. Run Discovery couple times:
2023-11-20 19:27:24.225 [info] Discover tests for workspace name: projects - uri: /Users/user/projects
2023-11-20 19:27:24.225 [info] Running discovery for pytest using the new test adapter.
2023-11-20 19:27:32.465 [info] Discover tests for workspace name: projects - uri: /Users/user/projects
2023-11-20 19:27:32.465 [info] Running discovery for pytest using the new test adapter.
2023-11-20 19:37:25.089 [info] Discover tests for workspace name: projects - uri: /Users/user/projects
2023-11-20 19:37:25.089 [info] Running discovery for pytest using the new test adapter.

nothing. 😦 No steps further of: https://github.com/microsoft/vscode-python/blob/f6cfa6e2cc89ab37f7d57096e19d3a9a77e441cf/src/client/testing/testController/controller.ts#L271

  1. As soon as I delete python.testing.cwd, it starts working. (But my real env needs python.testing.cwd, so no WA)

  2. If I Reload Window, I got:

2023-11-20 19:38:32.144 [info] > ./venv/bin/python -m pytest -p vscode_pytest --collect-only
2023-11-20 19:38:32.144 [info] cwd: pytest_issue
2023-11-20 19:38:32.636 [info] Starting Pylance language server.
2023-11-20 19:38:39.050 [info] Discover tests for workspace name: projects - uri: /Users/user/projects
2023-11-20 19:38:39.050 [info] Running discovery for pytest using the new test adapter.

In other times to --collect-only no calls. Silence.

Diagnostic data

  • Python version (& distribution if applicable, e.g. Anaconda): Cpython 3.9 - 3.11
  • Type of virtual environment used (e.g. conda, venv, virtualenv, etc.): Venv or Local
  • Value of the python.languageServer setting: Default
  • I tried on Darwing, Ubuntu, Centos
  • Local env was used with Remote SSH. While ven fully on host - as repro.
Output for Python in the Output panel (View→Output, change the drop-down the upper-right of the Output panel to Python)

2023-11-20 19:27:24.225 [info] Discover tests for workspace name: projects - uri: /Users/user/projects
2023-11-20 19:27:24.225 [info] Running discovery for pytest using the new test adapter.
2023-11-20 19:27:32.465 [info] Discover tests for workspace name: projects - uri: /Users/user/projects
2023-11-20 19:27:32.465 [info] Running discovery for pytest using the new test adapter.
2023-11-20 19:37:25.089 [info] Discover tests for workspace name: projects - uri: /Users/user/projects
2023-11-20 19:37:25.089 [info] Running discovery for pytest using the new test adapter.

User Settings

    "python.testing.cwd": "pytest_issue",
    "python.testing.pytestArgs": [],
    "python.testing.unittestEnabled": false,
    "python.testing.pytestEnabled": true,

Extension version: 2023.20.0 VS Code version: Code 1.84.2 (Universal) (1a5daa3a0231a0fbba4f14db7ec463cf99d7768e, 2023-11-09T10:52:33.687Z) OS version: Darwin arm64 23.1.0 Modes:

System Info
Item Value
CPUs Apple M2 Max (12 x 24)
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
video_decode: enabled
video_encode: enabled
vulkan: disabled_off
webgl: enabled
webgl2: enabled
webgpu: enabled
Load (avg) 1, 2, 2
Memory (System) 96.00GB (29.92GB free)
Process Argv –crash-reporter-id 0ddd1806-9bb8-4a88-8fc3-dfe586936e48
Screen Reader no
VM 0%
A/B Experiments
vsliv368:30146709
vsreu685:30147344
python383cf:30185419
vspor879:30202332
vspor708:30202333
vspor363:30204092
vswsl492:30256859
vslsvsres303:30308271
vserr242cf:30382550
pythontb:30283811
vsjup518:30340749
pythonptprofiler:30281270
vshan820:30294714
vstes263cf:30335440
vscod805:30301674
binariesv615:30325510
bridge0708:30335490
bridge0723:30353136
vsaa593:30376534
pythonvs932:30410667
py29gd2263:30880072
vsclangdc:30486549
c4g48928:30535728
dsvsc012cf:30540253
pynewext54:30695312
azure-dev_surveyone:30548225
282f8724:30602487
f6dab269:30613381
2i9eh265:30646982
showlangstatbar:30737416
pythonfmttext:30731395
fixshowwlkth:30771522
showindicator:30805244
pythongtdpath:30769146
i26e3531:30792625
pythonnosmt12:30797651
pythonidxpt:30866567
pythonnoceb:30805159
synctok:30869157
dsvsc013:30795093
dsvsc014:30804076
dsvsc015:30845448
pythontestfixtcf:30871695
pythonregdiag2:30871582
pyreplss1:30897532
pythonmypyd1:30879173
pythoncet0:30885854
2e7ec940:30885897
pythontbext0:30879054
dsvsc016cf:30886111
dsvsc017:30886112
dsvsc018cf:30886115
aa_t_chat:30882232

About this issue

  • Original URL
  • State: open
  • Created 7 months ago
  • Reactions: 3
  • Comments: 18 (9 by maintainers)

Most upvoted comments

able to repro- will investigate!

@eleanorjboyd, github-actions is worried that something is needed. 😃

Lookiing forward for:

  • nicer logging
  • (optionally) for relative path, no need to use . (dot). As it used to work.

ah yes this makes sense “After proper setting of cwd need vscode restart. “Refresh Tests” is useless.”, I am looking into why the extension doesn’t error out but it has a behavior where if discovery is already running it will not run again even with new args because discovery is expensive. As I work to figure out how to get the extension to error out on the wrong cwd I had added some logging to notify the user that discovery is not being re-run, hopefully this will help the next user. Sorry for the difficulty! https://github.com/microsoft/vscode-python/commit/a05dee86b3441b2b75371f05292195c35266b18c

Happy to see this reported as I’m also suddenly experiencing this issue as well:

image

image

BUT If I revert to version 1.83, it works as expected and doesn’t get stuck.

image image