-
Notifications
You must be signed in to change notification settings - Fork 230
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
-nauto isn't smart enough #853
Comments
In the current architecture this is not possible, because we start by spawning workers, which themselves do the collection. |
I am doing this, but it takes a bit of monkeypatch or changes to xdist. I have added code to xdist to start another node dynamically when all the nodes are busy. This also allows removal of nodes that are no longer needed. This bit of "magic" is required to be inserted into dsession (either by monkepatching or just modify your version) to support this: def start_new_node_with_env(self, env):
""" start a new node with specified environment variables
this can be used to start a worker with a specific configuration
and scheduler can assign work based on that configuration.
"""
import execnet
spec = execnet.XSpec("popen")
self.nodemanager.group.allocate_id(spec)
self.trdist._specs.append(spec)
self.trdist.setstatus(spec, "I", show=True)
spec.env.update(env)
node =self.nodemanager.setup_node(spec, self.queue.put)
self._active_nodes.add(node)
return node There are some issues schedulers logic getting confused when a new node comes along that need tweaked also. But the changes are minor and relate to collection tracking. My fork has this change as well as several other improvements to scheduling. There looks to be some other development revolving around work stealing, however I don't understand how pytest teardown works with such a concept. |
i came up with this workaround which seems to work well in vscode: // .vscode/settings.json
{
"python.testing.pytestArgs": ["-n", "auto"]
} # conftest.py
@hookimpl(wrapper=True)
def pytest_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 = yield
if "vscode_pytest" in config.option.plugins:
return min(num_workers, len(config.option.file_or_dir))
return num_workers this works because vscode passes each test to pytest as separate arguments (eg. 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 user {
"python.experiments.optInto": ["pythonTestAdapter"]
} |
The above patch from @DetachHead almost worked for me. I did have to add |
that's odd. what version of xdist are you using? for me it just returns an |
I'll try updating and see if I can remove that line. |
pytest-xdist-3.5.0 |
ah, it sounds like you're using |
-nauto
is fine for deciding how many processes you need based on processors, but it should wait and make it's decision AFTER tests have been collected and filtered and if the number of tests to run is less than the number of processors, it should scale back and only start as many processes as are needed. This will probably mean that it takes a tiny bit longer to get started but if you are using vscode and debugging tests, you won't spawn 10 processes and only use 1 of them. Maybe this behavior is only needed if there are tests specified on the command line (which would mean it wouldn't slow down full test runs).The text was updated successfully, but these errors were encountered: