-
Notifications
You must be signed in to change notification settings - Fork 1.3k
Description
Hello, I would like to start using vscode for debuging Python tests. We are using the pytest framework. I read online some guidelines on how to set up the tests UI in VSCode.
I added the following in my global settings.json:
"python.testing.unittestEnabled": false,
"python.testing.pytestEnabled": true,
"python.testing.autoTestDiscoverOnSaveEnabled": true,And we are using this configuration in pyproject.toml file:
[tool.pytest.ini_options]
addopts = """
--verbose
--ruff
--mypy
"""
asyncio_mode = "auto"With this I started to see some tests in the UI:

but that is just incorrect..
Then I tried adding "python.testing.pytestArgs": ["tests"], into the global settings.json and it starts to show the test folder correctly and even picks up all the tests according to the logs, but it only shows this in the menu and no "play arrows" are "inlined" into the code near the test function definitions:

Finally when I add just empty pytest.ini file to the root dir, and I can then remove this "python.testing.pytestArgs": ["tests"], from the global settings.json file and it starts to work properly, or rather it shows all the tests now properly with inlined "play" buttons to run them one by one from the code.
However it still does not pick up the configuration from the pyproject.toml file so to get it working properly I need to add this to the file and now the tests work properly and I am even able to start debugger over them:
[pytest]
asyncio_mode = autoMy question is why does this happen, like why does not the extension pick up the pytest configuration from the pyproject.toml file please? I tried multiple times fiddling with the arguments for the pytest etc. but I was not able to get it working without the pytest.ini file.
I think that my options are either to insert this file to every our repo (we have them around 200) and force this change to everyone else using other IDEs that does not pose this issue or I can add a script that is run every time I create my poetry venv for each project that inserts the pytest.ini file. Either option works but is kind of cumbersome.
So I started looking into the source code of the extension and found this:
vscode-python/src/client/testing/configuration/pytest/testConfigurationManager.ts
Line 53 in 9f6735e
| const promises = ['pytest.ini', 'tox.ini', 'setup.cfg'].map(async (cfg) => |
Should not also be there the pyproject.toml? At every other place there is pytest.ini there is the pyproject.toml but not here. I wanted to verify this change but I am failing to run the recompiled extension successfully (I managed to get it installed just now, but it still refuess to start up properly).
I found some similar issues but without any resolution that would apply to my case for example these:
#10722
#22643
My vscode version is:
❯_ code --version
1.93.1
x64
And the extension version is:
v2024.14.1
Appriciate any kind of help with this. Thanks!