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

# Testing

> Write and run pytest tests against your V-Run Python workflows in the same cloud sandbox as production — so every commit ships verified code.

V-Run has built-in testing so you can verify your workflow logic before you commit.

## Writing tests

Switch to the **Test** tab in the editor and write standard pytest tests against your main code.

```python theme={null}
from main import parse_articles

def test_parse_articles_returns_list():
    html = "<html><body><h2>Article 1</h2><h2>Article 2</h2></body></html>"
    result = parse_articles(html)
    assert isinstance(result, list)
    assert len(result) == 2

def test_parse_articles_empty_page():
    html = "<html><body></body></html>"
    result = parse_articles(html)
    assert result == []
```

Your test code can import functions from `main` (your main code file) directly.

## Running tests

Click **Run Tests** in the editor toolbar. Tests execute in the same cloud sandbox as production runs, so the environment is identical.

Results display in the bottom panel with:

* **Pass/fail status** for each test
* **stdout and stderr** output
* **Execution time**

<Tip>
  Run tests frequently during development. They execute in seconds and catch issues before they reach production.
</Tip>

## Test requirements

If your tests need additional packages (e.g. `pytest-mock`, `responses`), add them to the test requirements file. These are installed alongside your main requirements during test execution.

## Best practices

* **Test each function independently.** Import individual functions from your main code rather than running the whole workflow.
* **Cover edge cases.** Test empty inputs, malformed data, and error conditions.
* **Keep tests fast.** Mock external APIs and databases when testing locally to keep the feedback loop tight.
* **Test before committing.** Make it a habit to run the full test suite before you commit a new version.
