gemini-code-assist[bot] commented on code in PR #19945:
URL: https://github.com/apache/tvm/pull/19945#discussion_r3524036816


##########
tests/scripts/setup-pytest-env.sh:
##########
@@ -76,10 +76,18 @@ function run_pytest() {
 
     suite_name="${test_suite_name}-${current_shard}-${ffi_type}"
 
-    DEFAULT_PARALLELISM=1
+    DEFAULT_PARALLELISM=auto
 
-    if [[ ! "${extra_args[*]}" == *" -n"* ]] && [[ ! "${extra_args[*]}" == *" 
-dist"* ]]; then
-        extra_args+=("-n=$DEFAULT_PARALLELISM")
+    # Keep the default scoped to run_pytest so nested and one-off pytest
+    # invocations do not recursively start workers.  Explicit options from
+    # either the environment or the caller remain authoritative.
+    pytest_args=" ${PYTEST_ADDOPTS:-} ${extra_args[*]} "
+    if [[ "${pytest_args}" != *" -n"* ]] &&
+       [[ "${pytest_args}" != *" --numprocesses"* ]] &&
+       [[ "${pytest_args}" != *" --dist"* ]] &&
+       [[ "${pytest_args}" != *" -d "* ]] &&
+       [[ "${pytest_args}" != *" --tx"* ]]; then
+        extra_args+=("-n=$DEFAULT_PARALLELISM" "--dist=loadgroup")
     fi

Review Comment:
   ![medium](https://www.gstatic.com/codereviewagent/medium-priority.svg)
   
   If `pytest-xdist` is not installed in the local environment, appending 
`-n=auto` by default will cause `pytest` to fail immediately with an `unknown 
command line option: -n` error.
   
   To improve the local developer experience and prevent breaking existing 
setups that do not have `pytest-xdist` installed, we should check if the plugin 
is available before appending the parallelization flags, similar to how we 
check for `reruns` on line 70.
   
   ```suggestion
       has_xdist=$(python3 -m pytest --help 2>&1 | grep 'numprocesses' || true)
       if [ -n "$has_xdist" ] &&
          [[ "${pytest_args}" != *" -n"* ]] &&
          [[ "${pytest_args}" != *" --numprocesses"* ]] &&
          [[ "${pytest_args}" != *" --dist"* ]] &&
          [[ "${pytest_args}" != *" -d "* ]] &&
          [[ "${pytest_args}" != *" --tx"* ]]; then
           extra_args+=("-n=$DEFAULT_PARALLELISM" "--dist=loadgroup")
       fi
   ```



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]


---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to