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

# fixtures

# `prefect.testing.fixtures`

## Functions

### `add_prefect_loggers_to_caplog` <sup>[https://github.com/PrefectHQ/prefect/blob/main/src/prefect/testing/fixtures.py#L49](https://github.com/PrefectHQ/prefect/blob/main/src/prefect/testing/fixtures.py#L49)</sup>

```python theme={null}
add_prefect_loggers_to_caplog(caplog: pytest.LogCaptureFixture) -> Generator[None, None, None]
```

### `is_port_in_use` <sup>[https://github.com/PrefectHQ/prefect/blob/main/src/prefect/testing/fixtures.py#L63](https://github.com/PrefectHQ/prefect/blob/main/src/prefect/testing/fixtures.py#L63)</sup>

```python theme={null}
is_port_in_use(port: int) -> bool
```

### `hosted_api_server` <sup>[https://github.com/PrefectHQ/prefect/blob/main/src/prefect/testing/fixtures.py#L69](https://github.com/PrefectHQ/prefect/blob/main/src/prefect/testing/fixtures.py#L69)</sup>

```python theme={null}
hosted_api_server(unused_tcp_port_factory: Callable[[], int], test_database_connection_url: Optional[str]) -> AsyncGenerator[str, None]
```

Runs an instance of the Prefect API server in a subprocess instead of the using the
ephemeral application.

Uses the same database as the rest of the tests.

### `use_hosted_api_server` <sup>[https://github.com/PrefectHQ/prefect/blob/main/src/prefect/testing/fixtures.py#L167](https://github.com/PrefectHQ/prefect/blob/main/src/prefect/testing/fixtures.py#L167)</sup>

```python theme={null}
use_hosted_api_server(hosted_api_server: str) -> Generator[str, None, None]
```

Sets `PREFECT_API_URL` to the test session's hosted API endpoint.

### `disable_hosted_api_server` <sup>[https://github.com/PrefectHQ/prefect/blob/main/src/prefect/testing/fixtures.py#L181](https://github.com/PrefectHQ/prefect/blob/main/src/prefect/testing/fixtures.py#L181)</sup>

```python theme={null}
disable_hosted_api_server() -> Generator[None, None, None]
```

Disables the hosted API server by setting `PREFECT_API_URL` to `None`.

### `enable_ephemeral_server` <sup>[https://github.com/PrefectHQ/prefect/blob/main/src/prefect/testing/fixtures.py#L194](https://github.com/PrefectHQ/prefect/blob/main/src/prefect/testing/fixtures.py#L194)</sup>

```python theme={null}
enable_ephemeral_server(disable_hosted_api_server: None) -> Generator[None, None, None]
```

Enables the ephemeral server by setting `PREFECT_SERVER_EPHEMERAL_ENABLED` to `True`.

### `mock_anyio_sleep` <sup>[https://github.com/PrefectHQ/prefect/blob/main/src/prefect/testing/fixtures.py#L211](https://github.com/PrefectHQ/prefect/blob/main/src/prefect/testing/fixtures.py#L211)</sup>

```python theme={null}
mock_anyio_sleep(monkeypatch: pytest.MonkeyPatch) -> Generator[Callable[[float], None], None, None]
```

Mock sleep used to not actually sleep but to set the current time to now + sleep
delay seconds while still yielding to other tasks in the event loop.

Provides "assert\_sleeps\_for" context manager which asserts a sleep time occurred
within the context while using the actual runtime of the context as a tolerance.

### `recorder` <sup>[https://github.com/PrefectHQ/prefect/blob/main/src/prefect/testing/fixtures.py#L313](https://github.com/PrefectHQ/prefect/blob/main/src/prefect/testing/fixtures.py#L313)</sup>

```python theme={null}
recorder() -> Recorder
```

### `puppeteer` <sup>[https://github.com/PrefectHQ/prefect/blob/main/src/prefect/testing/fixtures.py#L318](https://github.com/PrefectHQ/prefect/blob/main/src/prefect/testing/fixtures.py#L318)</sup>

```python theme={null}
puppeteer() -> Puppeteer
```

### `events_server` <sup>[https://github.com/PrefectHQ/prefect/blob/main/src/prefect/testing/fixtures.py#L323](https://github.com/PrefectHQ/prefect/blob/main/src/prefect/testing/fixtures.py#L323)</sup>

```python theme={null}
events_server(unused_tcp_port: int, recorder: Recorder, puppeteer: Puppeteer) -> AsyncGenerator[Server, None]
```

### `events_api_url` <sup>[https://github.com/PrefectHQ/prefect/blob/main/src/prefect/testing/fixtures.py#L426](https://github.com/PrefectHQ/prefect/blob/main/src/prefect/testing/fixtures.py#L426)</sup>

```python theme={null}
events_api_url(events_server: Server, unused_tcp_port: int) -> str
```

### `events_cloud_api_url` <sup>[https://github.com/PrefectHQ/prefect/blob/main/src/prefect/testing/fixtures.py#L431](https://github.com/PrefectHQ/prefect/blob/main/src/prefect/testing/fixtures.py#L431)</sup>

```python theme={null}
events_cloud_api_url(events_server: Server, unused_tcp_port: int) -> str
```

### `mock_should_emit_events` <sup>[https://github.com/PrefectHQ/prefect/blob/main/src/prefect/testing/fixtures.py#L436](https://github.com/PrefectHQ/prefect/blob/main/src/prefect/testing/fixtures.py#L436)</sup>

```python theme={null}
mock_should_emit_events(monkeypatch: pytest.MonkeyPatch) -> mock.Mock
```

### `asserting_events_worker` <sup>[https://github.com/PrefectHQ/prefect/blob/main/src/prefect/testing/fixtures.py#L444](https://github.com/PrefectHQ/prefect/blob/main/src/prefect/testing/fixtures.py#L444)</sup>

```python theme={null}
asserting_events_worker(monkeypatch: pytest.MonkeyPatch) -> Generator[EventsWorker, None, None]
```

### `asserting_and_emitting_events_worker` <sup>[https://github.com/PrefectHQ/prefect/blob/main/src/prefect/testing/fixtures.py#L457](https://github.com/PrefectHQ/prefect/blob/main/src/prefect/testing/fixtures.py#L457)</sup>

```python theme={null}
asserting_and_emitting_events_worker(monkeypatch: pytest.MonkeyPatch) -> Generator[EventsWorker, None, None]
```

### `events_pipeline` <sup>[https://github.com/PrefectHQ/prefect/blob/main/src/prefect/testing/fixtures.py#L470](https://github.com/PrefectHQ/prefect/blob/main/src/prefect/testing/fixtures.py#L470)</sup>

```python theme={null}
events_pipeline(asserting_events_worker: EventsWorker) -> AsyncGenerator[EventsPipeline, None]
```

### `emitting_events_pipeline` <sup>[https://github.com/PrefectHQ/prefect/blob/main/src/prefect/testing/fixtures.py#L521](https://github.com/PrefectHQ/prefect/blob/main/src/prefect/testing/fixtures.py#L521)</sup>

```python theme={null}
emitting_events_pipeline(asserting_and_emitting_events_worker: EventsWorker) -> AsyncGenerator[EventsPipeline, None]
```

### `reset_worker_events` <sup>[https://github.com/PrefectHQ/prefect/blob/main/src/prefect/testing/fixtures.py#L540](https://github.com/PrefectHQ/prefect/blob/main/src/prefect/testing/fixtures.py#L540)</sup>

```python theme={null}
reset_worker_events(asserting_events_worker: EventsWorker) -> Generator[None, None, None]
```

## Classes

### `Recorder` <sup>[https://github.com/PrefectHQ/prefect/blob/main/src/prefect/testing/fixtures.py#L282](https://github.com/PrefectHQ/prefect/blob/main/src/prefect/testing/fixtures.py#L282)</sup>

### `Puppeteer` <sup>[https://github.com/PrefectHQ/prefect/blob/main/src/prefect/testing/fixtures.py#L295](https://github.com/PrefectHQ/prefect/blob/main/src/prefect/testing/fixtures.py#L295)</sup>
