Skip to content

tests are not being discovered #22018

Closed as not planned
Closed as not planned

Description

Type: Bug

Tests for python project are not appearing in VS Code.

In the terminal output I foud the command that is executed.
This command returns proper tests

$ ~/.cache/pypoetry/virtualenvs/vox-7_rKBGgW-py3.11/bin/python ~/.vscode/extensions/ms-python.python-2023.16.0/pythonFiles/testing_tools/run_adapter.py discover pytest -- --rootdir . -s --cache-clear .
[{"rootid": ".", "root": "/storage/amoje/Sync/area22/vox2", "parents": [{"id": "./src", "kind": "folder", "name": "src", "parentid": ".", "relpath": "./src"}, {"id": "./src/vox", "kind": "folder", "name": "vox", "parentid": "./src", "relpath": "./src/vox"}, {"id": "./src/vox/test_main.py", "kind": "file", "name": "test_main.py", "parentid": "./src/vox", "relpath": "./src/vox/test_main.py"}], "tests": [{"id": "./src/vox/test_main.py::test_read_main", "name": "test_read_main", "source": "./src/vox/test_main.py:13", "markers": [], "parentid": "./src/vox/test_main.py"}, {"id": "./src/vox/test_main.py::test_comedy_tom_hanks", "name": "test_comedy_tom_hanks", "source": "./src/vox/test_main.py:20", "markers": [], "parentid": "./src/vox/test_main.py"}]}]

VS Code version: Code 1.82.2 (abd2f3db4bdb28f9e95536dfa84d8479f1eb312d, 2023-09-14T05:51:20.981Z)
OS version: Linux x64 6.2.0-32-generic snap
Modes:

System Info
Item Value
CPUs AMD Ryzen 9 5900X 12-Core Processor (24 x 2200)
GPU Status 2d_canvas: enabled
canvas_oop_rasterization: disabled_off
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: disabled_software
vulkan: disabled_off
webgl: enabled
webgl2: enabled
webgpu: disabled_off
Load (avg) 0, 1, 1
Memory (System) 62.71GB (51.43GB free)
Process Argv --no-sandbox --force-user-env --unity-launch --crash-reporter-id cccdcc23-b3ed-4860-8b66-fadc67e8d915
Screen Reader no
VM 0%
DESKTOP_SESSION ubuntu
XDG_CURRENT_DESKTOP Unity
XDG_SESSION_DESKTOP ubuntu
XDG_SESSION_TYPE x11
Extensions (43)
Extension Author (truncated) Version
terraform 4op 0.2.5
vscode-markdownlint Dav 0.51.0
gitlens eam 14.3.0
remotehub Git 0.60.0
go gol 0.39.1
terraform has 2.27.2
vscode-python-timeit Has 1.3.8
file-downloader min 1.0.12
prettify-json moh 0.0.3
black-formatter ms- 2023.4.1
isort ms- 2023.10.1
pylint ms- 2023.6.0
python ms- 2023.16.0
vscode-pylance ms- 2023.9.10
jupyter ms- 2023.8.1002501831
jupyter-keymap ms- 1.1.2
jupyter-renderers ms- 1.0.17
vscode-jupyter-cell-tags ms- 0.1.8
vscode-jupyter-slideshow ms- 0.1.5
remote-containers ms- 0.309.0
remote-ssh ms- 0.106.4
remote-ssh-edit ms- 0.86.0
remote-wsl ms- 0.81.3
vscode-remote-extensionpack ms- 0.24.0
azure-repos ms- 0.36.0
remote-explorer ms- 0.4.1
remote-repositories ms- 0.38.1
remote-server ms- 1.4.3
remote-kubernetes Okt 0.4.10
vscode-circular-dependencies-finder ole 1.1.0
r-debugger RDe 0.5.4
java red 1.22.1
vscode-yaml red 1.14.0
markdown-preview-enhanced shd 0.7.9
intellicode-api-usage-examples Vis 0.2.8
vscodeintellicode Vis 1.2.30
keyoti-changeallendoflinesequence vs- 0.0.3
vscode-java-debug vsc 0.54.0
vscode-java-dependency vsc 0.23.1
vscode-java-pack vsc 0.25.14
vscode-java-test vsc 0.39.1
vscode-maven vsc 0.42.0
markdown-all-in-one yzh 3.5.1
A/B Experiments
vsliv368cf:30146710
vsreu685:30147344
python383:30185418
vspor879:30202332
vspor708:30202333
vspor363:30204092
vslsvsres303:30308271
vserr242:30382549
pythontb:30283811
vsjup518:30340749
pythonptprofiler:30281270
vshan820:30294714
vstes263:30335439
vscod805cf:30301675
binariesv615:30325510
bridge0708:30335490
bridge0723:30353136
vsaa593cf:30376535
pythonvs932:30410667
vsclangdc:30486549
c4g48928:30535728
dsvsc012cf:30540253
pynewext54:30695312
azure-dev_surveyone:30548225
vscccc:30803845
282f8724:30602487
89544117:30613380
showlangstatbar:30737416
962ge761:30835153
03d35959:30757346
pythonfmttext:30731395
fixshowwlkth:30771522
showindicator:30805244
pythongtdpath:30769146
i26e3531:30792625
pythonnosmt12:30797651
pythonidxpt:30805730
pythonnoceb:30805159
asynctok:30821568
dsvsc013:30795093
dsvsc014:30804076
diffeditorv1:30821571
dsvsc015:30829745

Activity

  1. gbajson-area22 commented on Sep 18, 2023

    @gbajson-area22
    Author

    This started to work when I opened my project from the realpath.
    I have a symlink to project dirs in my home dir and in that case it doesn't work.

    VS Code file opened as:
    /home/gbajson/Sync/area22/vox2/vox.code-workspace -- tests are not discovered

    VS Code file opened as:
    /storage/amoje/Sync/area22/vox2/vox.code-workspace -- tests are discovered

    $ ls -ld ~/Sync
    lrwxrwxrwx 1 gbajson gbajson 20 cze  3  2022 /home/gbajson/Sync -> /storage/amoje/Sync/
    
  2. eleanorjboyd commented on Sep 18, 2023

    @eleanorjboyd
    Member

    Hello! Could you try this on the rewrite of the testing infrastructure to see if it occurs here? You can do so by adding this setting to your users settings.json "python.experiments.optInto": ["pythonTestAdapter"].

    You can confirm you have the rewrite enabled by setting "python.analysis.logLevel": "Trace", in your user settings then check Experiment 'pythonTestAdapter' is active in your python logs.

    Let me know if the rewrite fixes your issue. Thanks!

  3. kbokh commented on Sep 20, 2023

    @kbokh

    The same problem with a symlink. Linux (EndeavourOS), vscode 1.82.2, a python 3.11 env managed by the poetry. The unittest can find tests but the pytest cannot. Pytest works well with a realpath

  4. eleanorjboyd commented on Sep 20, 2023

    @eleanorjboyd
    Member

    Can you clarify what your setup is with the two root paths? Are those on the same computer? I have been trying to repro this symlink issue but have been unable to. If you are able to review the steps I took here and let me know how your setup differs that would be very helpful! #21373

    Hello! I got a setup working on a parallels VM. I have a windows VM with parallels then have WSL on that machine to a Ubuntu machine. These are the steps I took and am still not able to repro. Any steps I am missing / did incorrectly?

    1. connect via WSL
    2. open vscode while connected via WSL
    3. create a folder called "purple_tiger"
    4. add a folder called "pink_tiger"
    5. create a test file "test_pink_tiger.py" with a single pytest in it
    6. get pytest running and the test explorer working in a vscode window with this folder
    7. create a symlink between the "purple_tiger" folder on my WSL and "tiger_alias" on my windows parallels VM, with a powershell command like this New-Item -ItemType SymbolicLink -Path "C:\Users\eleanorboyd\Documents\python-tester-files\tiger_alias" -Target "\\wsl$\Ubuntu\home\linux_user\linux_root\purple_tiger"
    8. run cd "C:\Users\eleanorboyd\Documents\python-tester-files\tiger_alias"
    9. now in that folder run code .
    10. now with vscode launched, open the python file so the extension is activated
    11. click the test icon on the left hand bar
    12. click to configure tests, selected "pink_tiger" as my test folder
    13. tests show up and run as expected
  5. rohanaras commented on Sep 25, 2023

    @rohanaras

    Can confirm that I have a similar issue as well.

    Can you clarify what your setup is with the two root paths? Are those on the same computer?

    My file paths look like this:

    ~/repos/[git-repo-name]

    where I have the symlink

    repos -> /mnt/data_science/rohana/repos,

    ~ is /home/rohana1,

    and /mnt/data_science is a nfs file share.

    Opening any repository from /home/rohana/repos results in no tests being discovered, whereas all tests are discovered when I open any repository from /mnt/data_science/rohana/repos

    Running pytest from the terminal works in both places.

    Could you try this on the rewrite of the testing infrastructure to see if it occurs here? You can do so by adding this setting to your users settings.json "python.experiments.optInto": ["pythonTestAdapter"].

    Tried doing this, couldn't figure out how to confirm that the rewrite was working (should Experiment 'pythonTestAdapter' have shown up under OUTPUT > Python?), but it didn't seem to fix the issue.

    System information:

    • Linux Rhel-8.7
    • VS Code 1.82.2
    • python 3.11.5 and 3.10 conda environments
    • pytest 7.4.2 and 7.4.0
  6. rohanaras commented on Sep 25, 2023

    @rohanaras

    Oh and one more thing: the output of

    conda run -n default --no-capture-output python ~/.vscode-server/extensions/ms-python.python-2023.16.0/pythonFiles/get_output_via_markers.py ~/.vscode-server/extensions/ms-python.python-2023.16.0/pythonFiles/testing_tools/run_adapter.py discover pytest -- --rootdir . -s --cache-clear .

    appears to list all tests when I run the command myself from the symlink version of the repositories

  7. eleanorjboyd commented on Oct 4, 2023

    @eleanorjboyd
    Member

    Hi Rohan Aras (@rohanaras) could you try this on the rewrite? It looks from the output you are still on the older code.

    To try it yourself, add this setting to your users settings.json "python.experiments.optInto": ["pythonTestAdapter"].

    You can confirm you have the rewrite enabled by setting "python.analysis.logLevel": "Trace", in your user settings then check for Experiment 'pythonTestAdapter' is active in your python logs.

    Let me know if the rewrite fixes your issue. Thanks!

  8. AdrianB-sovo commented on Oct 11, 2023

    @AdrianB-sovo

    For those using WSL on Windows, the "python.experiments.optOutFrom" will not be supported on your local user settings, you should use the remote user settings.
    ctrl + shift + p → "Preferences: Open Remote Settings (JSON)"

  9. 21 remaining items

  10. added
    bugIssue identified by VS Code Team member as probable bug
    and removed
    info-neededIssue requires more information from poster
    triage-neededNeeds assignment to the proper sub-team
    on Jan 25, 2024
  11. eleanorjboyd commented on Feb 26, 2024

    @eleanorjboyd
    Member

    Hello! This bug should be fixed and on vscode insiders! The release to vscode stable will be out by the end of the week. Please let me know if you try it on insiders or stable when it comes out and still doesn't work and I can investigate your specific issue further.

  12. locked as resolved and limited conversation to collaborators on Mar 29, 2024
  13. eleanorjboyd commented on Apr 15, 2024

    @eleanorjboyd
    Member

    Hi Alan Silva (@alanwilter), just got back from vacation and unlocked this. Could you describe the issue you are still seeing? Is it still the same setup as this? I have been testing it in a few scenarios and it has been working for me recently but I must still be missing a scenario. Thanks

    Thanks Eleanor Boyd (@eleanorjboyd), using dummy pytest.ini did the trick indeed. So it seems that the New Test does not accept /dev/null. It's a small price to pay.

    So, the only issue pending now it the symlink.

    If I do:

    ln -s cwd_specified llll
    code llll

    your example test won't work.

  14. eleanorjboyd commented on Apr 15, 2024

    @eleanorjboyd
    Member

    Also can you send over your pytest args when you describe your setup? I think this could be contributing if you already specific a cwd or rootdir but I would have to check further.

  15. eleanorjboyd commented on Apr 30, 2024

    @eleanorjboyd
    Member

    Hello again! Recently I have merged this PR which was very similar to your symlink issue. I think that merge should resolve this but please let me know if not and I can keep investigating. Thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Labels

area-testingbugIssue identified by VS Code Team member as probable buginfo-neededIssue requires more information from postertriage-neededNeeds assignment to the proper sub-team

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions