# How to Run Tests for the RLM Project: A Complete pytest Guide

> Learn how to run tests for the RLM project using pytest. Install dependencies and execute pytest from the repository root for comprehensive test coverage. Get started now.

- Repository: [az/rlm](https://github.com/alexzhang13/rlm)
- Tags: how-to-guide
- Published: 2026-06-18

---

**To run tests for the RLM project, install the development dependencies with `uv pip install -e ".[dev]"` and execute `uv run pytest` from the repository root to discover and execute all tests in the `tests/` directory.**

The RLM (Recursive Language Model) repository by alexzhang13 ships with a comprehensive pytest-based test suite located under the `tests/` directory. Running tests for the RLM project validates the core recursion logic, environment handlers, and language model client integrations before deployment.

## Prerequisites and Environment Setup

The RLM project targets Python 3.11+ and recommends using `uv` for fast dependency management. You must install the package in editable mode with development extras to access the testing tools.

### Install uv and Create a Virtual Environment

First, install the `uv` package manager if you do not have it already:

```bash
curl -LsSf https://astral.sh/uv/install.sh | sh

```

Create a fresh virtual environment with Python 3.12 (the recommended version for RLM):

```bash
uv init && uv venv --python 3.12
source .venv/bin/activate

```

### Install Development Dependencies

Install RLM in editable mode together with its test extras. The `dev` extra defined in [`pyproject.toml`](https://github.com/alexzhang13/rlm/blob/main/pyproject.toml) pulls in `pytest`, `ruff`, and other required tools:

```bash
uv pip install -e ".[dev]"

```

This command makes the `rlm` package importable from your test files while installing all necessary testing dependencies.

## Running the Test Suite

Once dependencies are installed, you can execute the full test suite or target specific modules.

### Execute All Tests

Run the complete test suite from the repository root:

```bash
uv run pytest

```

This command discovers all files matching `test_*.py` or `*_test.py` under the `tests/` directory and executes them. You should see output similar to:

```bash
============================= test session starts ==============================
platform linux -- Python 3.12.0, pytest-8.2.2, pluggy-1.5.0
collected 42 items

tests/test_local_repl.py::test_basic_execution PASSED
tests/test_rlm_query.py::test_rlm_query_recursion PASSED
============================== 42 passed in 3.14s ==============================

```

### Run Specific Test Files or Functions

For faster iteration, you can run a single test file or a specific test function using the `::` syntax:

```bash

# Run a specific test file

uv run pytest tests/test_local_repl.py

# Run a specific test function

uv run pytest tests/test_local_repl.py::test_basic_execution

```

This targeted approach is useful when debugging specific components like [`rlm/core/rlm.py`](https://github.com/alexzhang13/rlm/blob/main/rlm/core/rlm.py) or [`rlm/environments/local_repl.py`](https://github.com/alexzhang13/rlm/blob/main/rlm/environments/local_repl.py).

## Linting and Code Quality Checks

RLM enforces code style with **ruff**. Before committing changes, verify formatting and fix auto-correctable issues:

```bash
uv run ruff check --fix .
uv run ruff format .

```

Running these commands ensures your contributions match the project's style guidelines defined in [`pyproject.toml`](https://github.com/alexzhang13/rlm/blob/main/pyproject.toml).

## Test Coverage Overview

The RLM test suite validates several critical components across the codebase:

- **Core RLM logic** – The `RLM` class, recursion handling, and budget/timeout enforcement are tested in [`tests/test_rlm_query.py`](https://github.com/alexzhang13/rlm/blob/main/tests/test_rlm_query.py) and [`tests/test_depth_metadata.py`](https://github.com/alexzhang13/rlm/blob/main/tests/test_depth_metadata.py).
- **Environment implementations** – Correctness of the in-process `LocalREPL` (defined in [`rlm/environments/local_repl.py`](https://github.com/alexzhang13/rlm/blob/main/rlm/environments/local_repl.py)) as well as isolated Docker and Modal environments are verified in [`tests/test_local_repl.py`](https://github.com/alexzhang13/rlm/blob/main/tests/test_local_repl.py) and [`tests/test_ipython_repl.py`](https://github.com/alexzhang13/rlm/blob/main/tests/test_ipython_repl.py).
- **LM handler** – Socket protocol compliance and client routing for the TCP-based handler in [`rlm/core/lm_handler.py`](https://github.com/alexzhang13/rlm/blob/main/rlm/core/lm_handler.py) are checked in [`tests/test_lm_handler.py`](https://github.com/alexzhang13/rlm/blob/main/tests/test_lm_handler.py).
- **Parsing utilities** – Token counting, prompt parsing, and error handling utilities from [`rlm/utils/parsing.py`](https://github.com/alexzhang13/rlm/blob/main/rlm/utils/parsing.py) are validated in [`tests/test_parsing.py`](https://github.com/alexzhang13/rlm/blob/main/tests/test_parsing.py).
- **Client wrappers** – Sanity checks for OpenAI, Anthropic, Gemini, Portkey, and Azure clients reside in `tests/clients/*.py`.

## Summary

- Install development dependencies using `uv pip install -e ".[dev]"` to pull in `pytest` and `ruff`.
- Execute the full suite with `uv run pytest` or target specific tests using `uv run pytest tests/test_local_repl.py::test_basic_execution`.
- Verify code style with `uv run ruff check` and `uv run ruff format` before submitting changes.
- Key test files cover core logic ([`tests/test_rlm_query.py`](https://github.com/alexzhang13/rlm/blob/main/tests/test_rlm_query.py)), environments ([`tests/test_local_repl.py`](https://github.com/alexzhang13/rlm/blob/main/tests/test_local_repl.py)), and client integrations (`tests/clients/`).

## Frequently Asked Questions

### What Python version is required to run tests for the RLM project?

The RLM project requires Python 3.11 or higher, though Python 3.12 is recommended for development. Specify the version when creating your virtual environment with `uv venv --python 3.12`.

### How do I run only the tests for a specific module?

Use the file path with `uv run pytest` followed by the specific test path. For example, `uv run pytest tests/test_lm_handler.py` runs only the language model handler tests, while `uv run pytest tests/test_lm_handler.py::test_socket_protocol` runs a single function.

### Why does pytest report "module not found" errors?

This typically occurs when you have not installed RLM in editable mode. Ensure you ran `uv pip install -e ".[dev]"` from the repository root so that the `rlm` package and its submodules (like `rlm.core.rlm` and `rlm.utils.parsing`) are available in your Python path.

### How do I fix code style issues before committing changes?

Run `uv run ruff check --fix .` to automatically correct linting violations and `uv run ruff format .` to standardize code formatting. These commands ensure your code adheres to the style rules defined in [`pyproject.toml`](https://github.com/alexzhang13/rlm/blob/main/pyproject.toml).