> ## Documentation Index
> Fetch the complete documentation index at: https://docs.loadforge.com/llms.txt
> Use this file to discover all available pages before exploring further.

# Debugging Scripts

> How to debug a failing LoadForge test.

# Debugging Load Tests

> [!TIP]
>
> Keep your test scripts modular by separating test logic, data, and configuration. This makes debugging easier and allows for better test maintenance.

If your **LoadForge test fails**, it may be due to **errors in your Locustfile**. These could be simple **Python syntax errors** or issues with how the test is defined.

## 1. Use the Test Debugger

LoadForge provides a **built-in test debugger** that runs your test and attempts to send requests through it. This is the easiest way to diagnose common issues.

👉 Head over to the [**Test Debugger**](https://app.loadforge.com/tests/check) to get started.

> [!TIP]
>
> If your test isn't running, the debugger will highlight syntax errors, request failures, or misconfigurations in real time.

## 2. Test Locally

Before running a test in LoadForge, you can **validate your Locustfile locally** to catch syntax errors.

### **Check for Syntax Errors**

To ensure your test script is correctly formatted, save it as a Python file (`example.py`) and run:

```shell theme={null}
python -m py_compile example.py
```

This will catch **basic Python syntax errors** before you attempt a full test.

### **Run a Local Locust Test**

To execute your test locally, first install Locust and its dependencies:

```shell theme={null}
# Update package list and install system dependencies
sudo apt-get -y update
sudo apt-get -y install python3-pip libxml2-dev libxslt1-dev build-essential \
    python3-dev libzmq3-dev gcc libatk1.0-0 libatk-bridge2.0-0 libcups2 \
    libxcomposite1 libxdamage1 libxfixes3 libxrandr2 libgbm1 libxkbcommon0 \
    libpango-1.0-0 libcairo2 libasound2 libatspi2.0-0

# Install Python packages
sudo pip3 install --prefer-binary locust pyquery uuid gevent Flask gevent-websocket \
    greenlet itsdangerous Jinja2 linecache2 MarkupSafe mock msgpack pyzmq six \
    traceback2 unittest2 websocket-client Werkzeug jsonpath-ng PyMySQL sqlalchemy \
    pg8000 xmltodict pandas oauthlib splinter requests-oauthlib \
    websocket-client beautifulsoup4 web3 eth-account locust-plugins \
    locust-plugins[appinsights] opencensus==0.7.12 opencensus-ext-azure==1.0.6 Faker \
    datadog pyjwt pycryptodome python-socketio[client] cryptography xxhash requests \
    playwright locust-plugins[playwright]

# Install Playwright browsers
playwright install chrome chromium
```

Then, run your test using Locust:

```shell theme={null}
locust -f example.py --host https://YOUR_HOST_HERE -u 10 -r 10 \
    --run-time 1m --headless
```

This executes a **1-minute test** with **10 sample users**, helping you **identify issues before deploying to LoadForge**.

> [!TIP]
>
> If your test runs locally but fails in LoadForge, check for **network restrictions, authentication issues, or host validation problems**.

## 3. Additional Debugging Tips

### **Use ChatGPT for Debugging**

LoadForge test scripts follow a **Locust-based format**, which ChatGPT understands well. If you're stuck, try:

* **Copy-pasting your Locustfile into ChatGPT** and asking it to check for errors.
* **Describing your issue** and asking for debugging advice.
* **Requesting optimizations** to improve script performance.

> [!TIP]
>
> ChatGPT can help debug syntax errors, request failures, and suggest improvements to your load test.

### **Enable Logging in Locust**

If you're unsure what's failing, enable verbose logging by modifying your script:

```python theme={null}
import logging
logging.basicConfig(level=logging.DEBUG)
```

This will output detailed logs during the test execution, showing request failures and bottlenecks.

### **Check LoadForge Errors & Logs**

If your test **fails in LoadForge**, check:

* **Run Results Page** for error messages.
* **Response time metrics** to see if timeouts are occurring.
* **Error logs** for HTTP status codes (e.g., `401 Unauthorized`, `500 Internal Server Error`).

## 4. Request Support

If you still need help, **contact LoadForge support**:

* **Email:** [hello@loadforge.com](mailto:hello@loadforge.com)
* **Live Chat:** Available directly in the LoadForge dashboard.

The LoadForge team is happy to assist with **Locustfile issues, test configuration, and debugging complex scenarios**.

> [!TIP]
>
> If you're unsure what's wrong, share your **test script and error logs** with LoadForge support for faster troubleshooting.

By following these debugging steps, you can quickly diagnose and fix issues, ensuring smooth and reliable load tests in LoadForge!


This documentation is built and hosted on [Mintlify](https://mintlify.com), a developer documentation platform.