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

**URL:** <https://discuss.ray.io/t/how-do-i-run-unit-tests-for-ray-serve-pull-request/23547>\
**Category:** Ray Serve\
**Created:** [May 12, 2026, 1:45am UTC](https://discuss.ray.io/t/how-do-i-run-unit-tests-for-ray-serve-pull-request/23547 "2026-05-12T01:45:06Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![wanadzhar913](https://sea2.discourse-cdn.com/flex020/user_avatar/discuss.ray.io/wanadzhar913/32/8504_2.png) [@wanadzhar913](https://discuss.ray.io/u/wanadzhar913)\
**Post date:** [May 12, 2026, 1:45am UTC](https://discuss.ray.io/t/how-do-i-run-unit-tests-for-ray-serve-pull-request/23547/1 "2026-05-12T01:45:06Z")

</div>

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

```bash
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:

```bash
(.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)

```

---

<div class="post-metadata">

**Author:** ![RunLLM](https://sea2.discourse-cdn.com/flex020/user_avatar/discuss.ray.io/runllm/32/8249_2.png) [@RunLLM](https://discuss.ray.io/u/RunLLM)\
**Post date:** [May 12, 2026, 1:47am UTC](https://discuss.ray.io/t/how-do-i-run-unit-tests-for-ray-serve-pull-request/23547/2 "2026-05-12T01:47:06Z")

</div>

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:

```bash
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:

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

```

For more details on the development workflow and troubleshooting, see [Ray development guide](https://github.com/ray-project/ray/blob/master/doc/source/ray-contribute/development.rst).

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

Sources:

- [Ray development guide](https://github.com/ray-project/ray/blob/master/doc/source/ray-contribute/development.rst)

Hint: Mention @RunLLM in the post for followups.

---

<div class="post-metadata">

**Author:** ![wanadzhar913](https://sea2.discourse-cdn.com/flex020/user_avatar/discuss.ray.io/wanadzhar913/32/8504_2.png) [@wanadzhar913](https://discuss.ray.io/u/wanadzhar913)\
**Post date:** [May 13, 2026, 6:11pm UTC](https://discuss.ray.io/t/how-do-i-run-unit-tests-for-ray-serve-pull-request/23547/3 "2026-05-13T18:11:50Z")

</div>

This ended up working best! @RunLLM

```bash
ray/ci/env/install-bazel.sh
bazel build --jobs=2 //:ray_pkg # build ray._raylet from source
pytest -vs test_application_state.py

```

---

<div class="post-metadata">

**Author:** ![RunLLM](https://sea2.discourse-cdn.com/flex020/user_avatar/discuss.ray.io/runllm/32/8249_2.png) [@RunLLM](https://discuss.ray.io/u/RunLLM)\
**Post date:** [May 13, 2026, 6:14pm UTC](https://discuss.ray.io/t/how-do-i-run-unit-tests-for-ray-serve-pull-request/23547/4 "2026-05-13T18:14:06Z")

</div>

Yes, that’s a valid and recommended workflow for building and testing Ray from source. The steps are:

1. Install Bazel:

```bash
ray/ci/env/install-bazel.sh

```

2. Build Ray’s core package (including ray.\_raylet):

```bash
bazel build --jobs=2 //:ray_pkg

```

3. Run your desired test(s) with pytest:

```bash
pytest -vs test_application_state.py

```

This approach ensures that native extensions are built and Python dependencies are handled by pytest. For more, see [Ray development docs](https://github.com/ray-project/ray/blob/master/doc/source/ray-contribute/development.rst) and [community troubleshooting](https://discuss.ray.io/t/building-ray-from-source-update-axsearch/21978).

Would you like a detailed explanation of each step or troubleshooting tips?

Sources:

- [Ray development docs](https://github.com/ray-project/ray/blob/master/doc/source/ray-contribute/development.rst)
- [Community troubleshooting](https://discuss.ray.io/t/building-ray-from-source-update-axsearch/21978)

Hint: Mention @RunLLM in the post for followups.
