How do I run unit tests for Ray Serve Pull Request?

1. Severity of the issue: (select one)
None: I’m just curious or want clarification.
Low: Annoying but doesn’t hinder my work.
Medium: Significantly affects my productivity but can find a workaround.
High: Completely blocks me.

2. Environment:

  • Ray version:
  • Python version: 3.10.12
  • OS: Ubuntu/WSL
  • Cloud/Infrastructure:
  • Other libs/tools (if relevant):

3. What happened vs. what you expected:

  • Expected:
  • Actual:

Hi there, am trying to make a Pull Request to Ray for an issue. However, after running the following commands I’m met with an error. Can someone help me detail the exact step to run local unit tests with ray?

Here’s what I ran:

python3 -m venv .venv
source .venv/bin/activate
pip install -U https://s3-us-west-2.amazonaws.com/ray-wheels/latest/ray-3.0.0.dev0-cp310-cp310-manylinux2014_x86_64.whl
python3 python/ray/setup-dev.py -y

sudo apt-get update
sudo apt-get install -y build-essential curl clang-12 pkg-config psmisc unzip
ci/env/install-bazel.sh

curl -o- https://raw.githubusercontent.com/nvm-sh/nvm/v0.40.1/install.sh | bash
nvm install 14
nvm use 14

bazel test \
  //python/ray/serve/tests/unit:test_grpc_replica_result \
  //python/ray/serve/tests/unit:test_router \
  --test_output=errors

Output:

(.venv) faiq0913@MSI:~/open_source/ray/python/ray/serve/tests$ bazel test //python/ray/serve/tests/unit:test_grpc_replica_result //python/ray/serve/tests/unit:test_router --test_output=errors
WARNING: Build option --test_env has changed, discarding analysis cache (this can be expensive, see https://bazel.build/advanced/performance/iteration-speed).
INFO: Analyzed 2 targets (74 packages loaded, 836 targets configured).
FAIL: //python/ray/serve/tests/unit:test_grpc_replica_result (see /home/faiq0913/.cache/bazel/_bazel_faiq0913/1517eff5ec783726ab4b380961af1633/execroot/io_ray/bazel-out/k8-opt/testlogs/python/ray/serve/tests/unit/test_grpc_replica_result/test.log)
FAIL: //python/ray/serve/tests/unit:test_router (see /home/faiq0913/.cache/bazel/_bazel_faiq0913/1517eff5ec783726ab4b380961af1633/execroot/io_ray/bazel-out/k8-opt/testlogs/python/ray/serve/tests/unit/test_router/test.log)

INFO: From Testing //python/ray/serve/tests/unit:test_grpc_replica_result:
==================== Test output for //python/ray/serve/tests/unit:test_grpc_replica_result:
Traceback (most recent call last):
  File "/home/faiq0913/.cache/bazel/_bazel_faiq0913/1517eff5ec783726ab4b380961af1633/sandbox/linux-sandbox/2/execroot/io_ray/bazel-out/k8-opt/bin/python/ray/serve/tests/unit/test_grpc_replica_result.runfiles/io_ray/python/ray/serve/tests/unit/test_grpc_replica_result.py", line 5, in <module>
    import grpc
ModuleNotFoundError: No module named 'grpc'
================================================================================

INFO: From Testing //python/ray/serve/tests/unit:test_router:
==================== Test output for //python/ray/serve/tests/unit:test_router:
Traceback (most recent call last):
  File "/home/faiq0913/.cache/bazel/_bazel_faiq0913/1517eff5ec783726ab4b380961af1633/sandbox/linux-sandbox/1/execroot/io_ray/bazel-out/k8-opt/bin/python/ray/serve/tests/unit/test_router.runfiles/io_ray/python/ray/serve/tests/unit/test_router.py", line 11, in <module>
    import pytest
ModuleNotFoundError: No module named 'pytest'
================================================================================

INFO: Found 2 test targets...
INFO: Elapsed time: 6.461s, Critical Path: 0.32s
INFO: 12 processes: 8 internal, 4 linux-sandbox.
INFO: Build completed, 2 tests FAILED, 12 total actions

//python/ray/serve/tests/unit:test_grpc_replica_result FAILED in 0.2s
  /home/faiq0913/.cache/bazel/_bazel_faiq0913/1517eff5ec783726ab4b380961af1633/execroot/io_ray/bazel-out/k8-opt/testlogs/python/ray/serve/tests/unit/test_grpc_replica_result/test.log

//python/ray/serve/tests/unit:test_router FAILED in 0.2s
  /home/faiq0913/.cache/bazel/_bazel_faiq0913/1517eff5ec783726ab4b380961af1633/execroot/io_ray/bazel-out/k8-opt/testlogs/python/ray/serve/tests/unit/test_router/test.log

Executed 2 out of 2 tests: 2 fail locally.
(.venv)

Your Bazel tests are failing because required Python dependencies (like grpc and pytest) are missing from the Bazel test environment. To run Ray’s local unit tests, you should first install all test dependencies:

pip install -r ../../requirements.txt
pip install -r ../../requirements/test-requirements.txt

Then, run tests using either Bazel or pytest. For Bazel, ensure dependencies are available to Bazel’s sandbox, or use pytest directly:

python -m pytest -v -s unit/test_grpc_replica_result.py

For more details on the development workflow and troubleshooting, see Ray development guide.

Would you like a step-by-step breakdown or help with Bazel-specific dependency management?

Sources:

Hint: Mention @RunLLM in the post for followups.