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

Pytest discovery stuck #23298

Closed
cliffqbio opened this issue Apr 26, 2024 · 4 comments
Closed

Pytest discovery stuck #23298

cliffqbio opened this issue Apr 26, 2024 · 4 comments
Assignees
Labels
area-testing info-needed Issue requires more information from poster triage-needed Needs assignment to the proper sub-team

Comments

@cliffqbio
Copy link

Type: Bug

Behaviour

running tests discovery fails

Steps to reproduce:

  1. have settings.json with:
{
    "python.testing.pytestArgs": [
        "--no-cov",
        "./services/sys/tests/",
        "./services/api/tests/",
    ],
"python.testing.autoTestDiscoverOnSaveEnabled": true,
...
}
  1. save, tests are being found as expected
  2. update the settings and add this folder to the args:
    "./services/blueprints/tests/",
  3. save again to do tests discovery
  4. I get errors
[error] pytest test discovery error for workspace:  /Users/zuk.bar/dev/gemini 
 _pytest.nodes.Collector.CollectError: ImportError while importing test module '/Users/zuk.bar/dev/gemini/services/api/tests/test_api.py'.
Hint: make sure your test modules/packages have valid Python names.
Traceback:
../../.pyenv/versions/3.10.12/lib/python3.10/importlib/__init__.py:126: in import_module
    return _bootstrap._gcd_import(name[level:], package, level)
E   ModuleNotFoundError: No module named 'tests.test_api'
 Check Python Test Logs for more details.

_pytest.nodes.Collector.CollectError: ImportError while importing test module '/Users/zuk.bar/dev/gemini/services/api/tests/test_medicalkb.py'.
Hint: make sure your test modules/packages have valid Python names.
Traceback:
../../.pyenv/versions/3.10.12/lib/python3.10/importlib/__init__.py:126: in import_module
    return _bootstrap._gcd_import(name[level:], package, level)
E   ModuleNotFoundError: No module named 'tests.test_medicalkb'
 Check Python Test Logs for more details.

_pytest.nodes.Collector.CollectError: ImportError while importing test module '/Users/zuk.bar/dev/gemini/services/api/tests/test_patient.py'.
Hint: make sure your test modules/packages have valid Python names.
Traceback:
../../.pyenv/versions/3.10.12/lib/python3.10/importlib/__init__.py:126: in import_module
    return _bootstrap._gcd_import(name[level:], package, level)
E   ModuleNotFoundError: No module named 'tests.test_patient'
 Check Python Test Logs for more details.

_pytest.nodes.Collector.CollectError: import file mismatch:
imported module 'tests.test_umr' has this __file__ attribute:
  /Users/zuk.bar/dev/gemini/services/blueprints/tests/test_umr.py
which is not the same as the test file we want to collect:
  /Users/zuk.bar/dev/gemini/services/api/tests/test_umr.py
HINT: remove __pycache__ / .pyc files and/or use a unique basename for your test file modules
 Check Python Test Logs for more details.

Interrupted: 4 errors during collection
 Check Python Test Logs for more details.

Extension version: 2024.4.1
VS Code version: Code 1.88.1 (e170252f762678dec6ca2cc69aba1570769a5d39, 2024-04-10T17:43:08.196Z)
OS version: Darwin arm64 23.4.0
Modes:

  • Python version (& distribution if applicable, e.g. Anaconda): 3.10.12
  • Type of virtual environment used (e.g. conda, venv, virtualenv, etc.): Poetry
  • Value of the python.languageServer setting: Default
User Settings


languageServer: "Pylance"

testing
• pytestArgs: "<placeholder>"
• pytestEnabled: true

Installed Extensions
Extension Name Extension Id Version
advanced-new-file patbenatar.advanced-new-file 1.2.2
autoDocstring - Python Docstring Generator njpwerner.autodocstring 0.6.1
Dev Containers ms-vscode-remote.remote-containers 0.354.0
Django batisteo.vscode-django 1.15.0
Docker ms-azuretools.vscode-docker 1.29.0
ES7+ React/Redux/React-Native snippets dsznajder.es7-react-js-snippets 4.4.3
GitHub Codespaces GitHub.codespaces 1.16.19
GitHub Copilot GitHub.copilot 1.184.0
GitHub Copilot Chat GitHub.copilot-chat 0.14.1
GitHub Pull Requests GitHub.vscode-pull-request-github 0.86.1
GitLens — Git supercharged eamodio.gitlens 14.9.1
Go golang.go 0.41.4
HashiCorp Terraform hashicorp.terraform 2.30.1
IntelliCode VisualStudioExptTeam.vscodeintellicode 1.3.1
IntelliCode API Usage Examples VisualStudioExptTeam.intellicode-api-usage-examples 0.2.8
JavaScript and TypeScript Nightly ms-vscode.vscode-typescript-next 5.5.20240424
JavaScript Debugger ms-vscode.js-debug 1.88.0
JavaScript Debugger Companion Extension ms-vscode.js-debug-companion 1.1.2
Jinja wholroyd.jinja 0.0.8
Jupyter ms-toolsai.jupyter 2024.3.1
Jupyter Cell Tags ms-toolsai.vscode-jupyter-cell-tags 0.1.9
Jupyter Keymap ms-toolsai.jupyter-keymap 1.1.2
Jupyter Notebook Renderers ms-toolsai.jupyter-renderers 1.0.17
Jupyter Slide Show ms-toolsai.vscode-jupyter-slideshow 0.1.6
Makefile Tools ms-vscode.makefile-tools 0.9.10
Markdown Preview Enhanced shd101wyy.markdown-preview-enhanced 0.8.13
Numbered Bookmarks alefragnani.numbered-bookmarks 8.4.0
Pylance ms-python.vscode-pylance 2024.4.1
Pyright ms-pyright.pyright 1.1.360
Python ms-python.python 2024.4.1
Python Debugger ms-python.debugpy 2024.4.0
Python Environment Manager donjayamanne.python-environment-manager 1.2.4
Python Extended tushortz.python-extended-snippets 0.0.1
Python Extension Pack donjayamanne.python-extension-pack 1.7.0
Python Indent KevinRose.vsc-python-indent 1.18.0
Python Path mgesbert.python-path 0.0.14
Python Poetry zeshuaro.vscode-python-poetry 0.17.17
React zhang-renyang.vscode-react 0.0.5
Table Visualizer for JavaScript Profiles ms-vscode.vscode-js-profile-table 1.0.8
Terraform 4ops.terraform 0.2.5
Test Adapter Converter ms-vscode.test-adapter-converter 0.1.9
Test Explorer UI hbenl.vscode-test-explorer 2.21.1
System Info
Item Value
CPUs Apple M2 Pro (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
skia_graphite: disabled_off
video_decode: enabled
video_encode: enabled
webgl: enabled
webgl2: enabled
webgpu: enabled
Load (avg) 4, 3, 4
Memory (System) 16.00GB (0.32GB free)
Process Argv --crash-reporter-id 43161093-9af1-47a8-bfe2-ee00acef03ce
Screen Reader no
VM 0%
A/B Experiments
vsliv368:30146709
vspor879:30202332
vspor708:30202333
vspor363:30204092
vscod805:30301674
binariesv615:30325510
vsaa593:30376534
py29gd2263:31024239
c4g48928:30535728
azure-dev_surveyone:30548225
a9j8j154:30646983
962ge761:30959799
pythongtdpath:30769146
welcomedialogc:30910334
pythonidxpt:30866567
pythonnoceb:30805159
asynctok:30898717
pythontestfixt:30902429
pythonregdiag2:30936856
pyreplss1:30897532
pythonmypyd1:30879173
pythoncet0:30885854
h48ei257:31000450
pythontbext0:30879054
accentitlementst:30995554
dsvsc016:30899300
dsvsc017:30899301
dsvsc018:30899302
cppperfnew:31000557
d34g3935:30971562
fegfb526:30981948
bg6jg535:30979843
ccp2r3:30993541
dsvsc020:30976470
pythonait:31006305
jchc7451:30973076
gee8j676:31009558
chatpanelt:31018789
dsvsc021:30996838
945dj816:31013170
pythoncenvpt:31022790

@github-actions github-actions bot added the triage-needed Needs assignment to the proper sub-team label Apr 26, 2024
@eleanorjboyd
Copy link
Member

Hi! From your errors it seems like you might have some import errors within your test files like E ModuleNotFoundError: No module named 'tests.test_api'. I would suggest testing it from the integrated terminal and running this python -m pytest --no-cov ./services/sys/tests/ ./services/api/tests/ since this is exactly what we are running through the extension. Check the errors when you run this and once you get it running right from the integrated terminal it should work from the test explorer! If not let me know

@eleanorjboyd eleanorjboyd self-assigned this Apr 26, 2024
@github-actions github-actions bot added the info-needed Issue requires more information from poster label Apr 26, 2024
@cliffqbio
Copy link
Author

Thanks Elena!

this one works as expected:
python -m pytest --no-cov ./services/sys/tests/ ./services/api/tests/

but this one gives the errors below:
python -m pytest --no-cov ./services/sys/tests/ ./services/api/tests/ ./services/blueprints/tests/

errors:

___________________ ERROR collecting test_api.py ____________________
ImportError while importing test module '/Users/zuk.bar/dev/gemini/services/api/tests/test_api.py'.
Hint: make sure your test modules/packages have valid Python names.
Traceback:
../../.pyenv/versions/3.10.12/lib/python3.10/importlib/__init__.py:126: in import_module
    return _bootstrap._gcd_import(name[level:], package, level)
E   ModuleNotFoundError: No module named 'tests.test_api'
________________ ERROR collecting test_medicalkb.py _________________
ImportError while importing test module '/Users/zuk.bar/dev/gemini/services/api/tests/test_medicalkb.py'.
Hint: make sure your test modules/packages have valid Python names.
Traceback:
../../.pyenv/versions/3.10.12/lib/python3.10/importlib/__init__.py:126: in import_module
    return _bootstrap._gcd_import(name[level:], package, level)
E   ModuleNotFoundError: No module named 'tests.test_medicalkb'
_________________ ERROR collecting test_patient.py __________________
ImportError while importing test module '/Users/zuk.bar/dev/gemini/services/api/tests/test_patient.py'.
Hint: make sure your test modules/packages have valid Python names.
Traceback:
../../.pyenv/versions/3.10.12/lib/python3.10/importlib/__init__.py:126: in import_module
    return _bootstrap._gcd_import(name[level:], package, level)
E   ModuleNotFoundError: No module named 'tests.test_patient'
___________________ ERROR collecting test_umr.py ____________________
import file mismatch:
imported module 'tests.test_umr' has this __file__ attribute:
  /Users/zuk.bar/dev/gemini/services/blueprints/tests/test_umr.py
which is not the same as the test file we want to collect:
  /Users/zuk.bar/dev/gemini/services/api/tests/test_umr.py
HINT: remove __pycache__ / .pyc files and/or use a unique basename for your test file modules

if I run only "blueprints":
python -m pytest --no-cov ./services/blueprints/tests/

it passes....

I would say I tried these two variations:

"python.testing.pytestArgs": [
        "--no-cov",
        "./services/sys/tests/",
        "./services/api/tests/",
    ],

VS

    "python.testing.pytestArgs": [
        "--no-cov",
        "./services/blueprints/tests/"
    ],

both work individually, but if I add "blueprints" to the others, it just hangs because of these error probably.

We have a weird mono repo, with many "sub" poetry projects.
Maybe there is a way have a workspace that will maintain all of it?

@github-actions github-actions bot removed the info-needed Issue requires more information from poster label Apr 26, 2024
@eleanorjboyd
Copy link
Member

Hi! Sorry I am still a bit confused, can you clarify which worked using the extension and which worked from the integrated terminal? Were there any cases that work from the terminal but not using the test explorer? I can only really help with these cases as something not working in both would suggest an issue with project setup. Thanks!

@github-actions github-actions bot added the info-needed Issue requires more information from poster label May 6, 2024
@eleanorjboyd
Copy link
Member

Hello! I am closing this issue since we have not heard back on the above question, please comment with the requested information if you are still experiencing this problem and I can re-open it. Thanks

@eleanorjboyd eleanorjboyd closed this as not planned Won't fix, can't repro, duplicate, stale Jun 7, 2024
@github-actions github-actions bot locked as resolved and limited conversation to collaborators Jul 9, 2024
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
area-testing info-needed Issue requires more information from poster triage-needed Needs assignment to the proper sub-team
Projects
None yet
Development

No branches or pull requests

2 participants