Skip to content

redsun.testing

Pytest fixtures for testing components, sessions and services.

A suite loads them with -p redsun.testing, in addopts or on the command line. Loading them makes every test keep session settings, session logs, acquisition data and catalogs under its tmp_path, and drop the psygnal emissions it left queued. The module defines no qapp, so it combines with pytest-qt.

BuildSession

Bases: Protocol

Build a session, and hand it back typed as what was asked for.

__call__

__call__(
    container: type[SessionT] | SessionT,
    config: Source | Sequence[Source] | None = ...,
) -> SessionT

Build container, a session class made with config, or a session.

StartService

Bases: Protocol

Start a service as a session declaring it would, and hand it back.

__call__

__call__(
    name: str, launch: Launch, /, *, transport: str = ...
) -> Service

Start the service launch describes, declared under name.

transport is the one a session file names under services.transport: channel-access or pv-access.

build

build() -> Generator[BuildSession, None, None]

Return a function building a session, shut down when the test ends.

It takes a session class, made with the configuration given and laid over what the class declares, or a session already made. Sessions are shut down in reverse order; one the test shut down itself runs nothing again. A shutdown that raises does not stop the others: once every session has been shut down, the fixture raises that error, or an ExceptionGroup of all of them when more than one session raised.

log_directory

log_directory(
    tmp_path: Path, monkeypatch: MonkeyPatch
) -> Generator[Path, None, None]

Write session log files under tmp_path, closing any the test left open.

data_directory

data_directory(
    tmp_path: Path, monkeypatch: MonkeyPatch
) -> Path

Put the default root of acquisition files and catalogs under tmp_path.

config_home

config_home(
    monkeypatch: MonkeyPatch, tmp_path: Path
) -> Path

Keep saved session settings in a config folder under tmp_path.

empty_emission_queue

empty_emission_queue() -> Generator[None, None, None]

Drop every psygnal emission the test left queued for another thread.

Left queued, an emission is delivered by the next test running the event loop, to whatever its target has become; a destroyed widget ends the interpreter.

start_service

start_service(
    monkeypatch: MonkeyPatch,
) -> Generator[StartService, None, None]

Return a function starting a declared service, stopped when the test ends.

Once the services have stopped, their transports are released and the EPICS address lists they added themselves to are restored, as when a session ends.