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 does not show correct tests without pytest.ini file #24201

Open
lexi-k opened this issue Sep 27, 2024 · 0 comments
Open

Pytest does not show correct tests without pytest.ini file #24201

lexi-k opened this issue Sep 27, 2024 · 0 comments
Assignees
Labels
triage-needed Needs assignment to the proper sub-team

Comments

@lexi-k
Copy link

lexi-k commented Sep 27, 2024

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:
image
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:
image

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 = auto

My 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:

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!

@github-actions github-actions bot added the triage-needed Needs assignment to the proper sub-team label Sep 27, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
triage-needed Needs assignment to the proper sub-team
Projects
None yet
Development

No branches or pull requests

2 participants