You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
when debugging a (single) test with pytest, invocation of pytest should add -n 0 . This way multiple runners will not be used and start-up time is reduced.
Reacted by DetachHead, iwino, elad-eyal, scott-au, Aviv Eyal, Sebastian Schubert, Adrian Castro, Jiahao Li, Filip Jeremic, Justin Robinson and 2 more
Hi! We are looking to make changes to how we pass args so you could have multiple config types: microsoft/vscode-python#21845. Would this solve your issue? Otherwise it would need to be a separate feature request. Our general policy at this time is we are trying to edit the pytest args as little as possible since it is very hard to do right. With this in mind, I am hesistant to do a feature request that causes arg editing and this would require a larger team conversation if you do want to make this a separate feature request. Thanks
i guess a separate python.testing.pytestArgs for debug would be a suitable workaround. i would think you'd want this behavior to be out of the box but user configuration is fine too.
# conftest.py@hookimpl(wrapper=True)defpytest_xdist_auto_num_workers(config: Config) ->Generator[None, int, int]:
"""determine how many workers to use based on how many tests were selected in the test explorer"""num_workers=yieldif"vscode_pytest"inconfig.option.plugins:
returnmin(num_workers, len(config.option.file_or_dir))
returnnum_workers
this works because vscode passes each test to pytest as separate arguments (eg. pytest test_foo.py::test_foo test_foo.py::test_bar), so you can guess how many tests are going to run before they get collected.
edit: looks like this relies on vscode's new test adapter, which isn't yet enabled for all users. to enable it, you need to add this to your usersettings.json (doesn't work in the workspace one unfortunately):
Thanks for the feature request! We are going to give the community 60 days to provide 7 👍 upvotes on the opening comment to gauge general interest in this idea. If there's enough upvotes then we will consider this feature request in our future planning. If there's unfortunately not enough upvotes then we will close this issue.
im going to try to make a PR adding this feature, because i'm pretty sure that smalll pytest_xdist_auto_num_workers hook in my workaround is all that's needed
Activity
eleanorjboyd commentedon May 6, 2024
Hi! We are looking to make changes to how we pass args so you could have multiple config types: microsoft/vscode-python#21845. Would this solve your issue? Otherwise it would need to be a separate feature request. Our general policy at this time is we are trying to edit the pytest args as little as possible since it is very hard to do right. With this in mind, I am hesistant to do a feature request that causes arg editing and this would require a larger team conversation if you do want to make this a separate feature request. Thanks
elad-eyal commentedon May 6, 2024
i guess a separate python.testing.pytestArgs for debug would be a suitable workaround. i would think you'd want this behavior to be out of the box but user configuration is fine too.
cheers
DetachHead commentedon May 7, 2024
ideally, it should dynamically decide how many runners to use based on how many tests are selected: pytest-dev/pytest-xdist#853
i came up with a workaround that works well with vscode's new pytest test adapter: pytest-dev/pytest-xdist#853 (comment)
paulacamargo25 commentedon May 30, 2024
Thanks for the feature request! We are going to give the community 60 days to provide 7 👍 upvotes on the opening comment to gauge general interest in this idea. If there's enough upvotes then we will consider this feature request in our future planning. If there's unfortunately not enough upvotes then we will close this issue.
DetachHead commentedon May 31, 2024
im going to try to make a PR adding this feature, because i'm pretty sure that smalll
pytest_xdist_auto_num_workershook in my workaround is all that's neededDetachHead commentedon Jun 2, 2024
microsoft/vscode-python#23539
Add hook to `vscode_pytest` to determine number `xdist` workers to us…
eleanorjboyd commentedon Jun 20, 2024
Thank you DetachHead for contributing!
Add hook to `vscode_pytest` to determine number `xdist` workers to us…
Add hook to `vscode_pytest` to determine number `xdist` workers to us…
shakhovski commentedon Jul 12, 2024
DetachHead, It doesn't work with pytest 6.2.5.
Commenting out your change allows Test Explorer to work.
eleanorjboyd commentedon Jul 12, 2024
shakhovski we are looking to no longer support any pytest version below 7, if possible it is best to update to a newer version. Thanks!