---
title: ViceroyTestBase
summary: Base class for viceroy tests.
url: https://www.fastly.com/documentation/reference/compute/sdks/python/fastly_compute/testing/viceroy/class.ViceroyTestBase/
---

**Kind:** Class  
**Module:** [viceroy](https://www.fastly.com/documentation/reference/compute/sdks/python/fastly_compute/testing/viceroy/)  
**Package:** fastly-compute 0.1.3  
**Source:** https://github.com/fastly/compute-sdk-python/blob/2bffcc6d596a68bcc0b4342404641deff78e68f6/fastly_compute/testing/viceroy.py#L42

Base class for viceroy tests.

Provides common functionality for testing Fastly Compute services.
Inherit from this class and use the viceroy_server fixture.

This assumes your WASM file is already built. Use your build system
(e.g., Makefile) to ensure the WASM file is up to date before running tests.

```python
import pytest
from fastly_compute.testing import ViceroyTestBase

class TestMyService(ViceroyTestBase):
    def test_my_endpoint(self):
        response = self.get("/my-endpoint")
        assert response.status_code == 200
```

## Constants

### REQUEST_TIMEOUT

**Type:** `Any`  
**Default:** `10`  
**Flags:** read-only  
**Source:** https://github.com/fastly/compute-sdk-python/blob/2bffcc6d596a68bcc0b4342404641deff78e68f6/fastly_compute/testing/viceroy.py#L62

### WASM_FILE

**Type:** `Any`  
**Default:** `'build/bottle-app.composed.wasm'`  
**Flags:** read-only  
**Source:** https://github.com/fastly/compute-sdk-python/blob/2bffcc6d596a68bcc0b4342404641deff78e68f6/fastly_compute/testing/viceroy.py#L63

### VICEROY_CONFIG

**Type:** `Any`  
**Default:** `None`  
**Flags:** read-only  
**Source:** https://github.com/fastly/compute-sdk-python/blob/2bffcc6d596a68bcc0b4342404641deff78e68f6/fastly_compute/testing/viceroy.py#L73

## Methods

### get

**Flags:** static  
**Source:** https://github.com/fastly/compute-sdk-python/blob/2bffcc6d596a68bcc0b4342404641deff78e68f6/fastly_compute/testing/viceroy.py#L267

```python
get(path: str, **kwargs) -> requests.Response
```

Make a GET request to the viceroy server.

**Parameters**

- `path`: `str` — URL path to request
- `**kwargs`: `Any` (optional) — Additional arguments passed to requests.get()

**Returns**

`requests.Response`

The HTTP response

### post

**Flags:** static  
**Source:** https://github.com/fastly/compute-sdk-python/blob/2bffcc6d596a68bcc0b4342404641deff78e68f6/fastly_compute/testing/viceroy.py#L277

```python
post(path: str, **kwargs) -> requests.Response
```

Make a POST request to the viceroy server.

**Parameters**

- `path`: `str` — URL path to request
- `**kwargs`: `Any` (optional) — Additional arguments passed to requests.post()

**Returns**

`requests.Response`

The HTTP response

### request

**Flags:** static  
**Source:** https://github.com/fastly/compute-sdk-python/blob/2bffcc6d596a68bcc0b4342404641deff78e68f6/fastly_compute/testing/viceroy.py#L287

```python
request(method: str, path: str, **kwargs) -> requests.Response
```

Make an HTTP request to the viceroy server.

**Parameters**

- `method`: `str` — HTTP method (GET, POST, PUT, DELETE, etc.)
- `path`: `str` — URL path to request
- `**kwargs`: `Any` (optional) — Additional arguments passed to requests.request()

**Returns**

`requests.Response`

The HTTP response

### server

**Flags:** static  
**Source:** https://github.com/fastly/compute-sdk-python/blob/2bffcc6d596a68bcc0b4342404641deff78e68f6/fastly_compute/testing/viceroy.py#L67

```python
server() -> ViceroyServer
```

Access server properties.

**Returns**

`ViceroyServer`

### set_up_backends

**Flags:** static  
**Source:** https://github.com/fastly/compute-sdk-python/blob/2bffcc6d596a68bcc0b4342404641deff78e68f6/fastly_compute/testing/viceroy.py#L126

```python
set_up_backends(backends: dict[str, str])
```

Set up backends for testing.

Call this in setUpClass or as a class-level setup.

**Parameters**

- `backends`: `dict[str, str]`

  Dict mapping backend names to URLs
  e.g., {"httpbin": "http://127.0.0.1:8080"}

### viceroy_server

**Flags:** static  
**Source:** https://github.com/fastly/compute-sdk-python/blob/2bffcc6d596a68bcc0b4342404641deff78e68f6/fastly_compute/testing/viceroy.py#L138

```python
viceroy_server()
```

Start viceroy server for the duration of the test class.

This assumes the WASM file already exists. Use your build system
to ensure it's built before running tests.

**Returns**

Server instance with process, base_url, and captured output
