obsws-cli/tests/conftest.py
onyx-and-iris 87eb7752bd add bounds/crop/rotation flags to sceneitem transform
upd readme
upd changelog

upd tests

minor bump
2025-04-27 13:50:40 +01:00

104 lines
2.6 KiB
Python

"""pytest configuration file."""
import os
import obsws_python as obsws
from dotenv import find_dotenv, load_dotenv
def pytest_configure(config):
"""Call after command line options are parsed.
All plugins and initial conftest files are loaded.
"""
def pytest_sessionstart(session):
"""Call after the Session object is created.
Before performing collection and entering the run test loop.
"""
# Initialize the OBS WebSocket client
session.obsws = obsws.ReqClient(
host=os.environ['OBS_HOST'],
port=os.environ['OBS_PORT'],
password=os.environ['OBS_PASSWORD'],
timeout=5,
)
resp = session.obsws.get_version()
out = (
'Running tests with:',
f'OBS Client version: {resp.obs_version} with WebSocket version: {resp.obs_web_socket_version}',
)
print(' '.join(out))
load_dotenv(find_dotenv('.test.env'))
session.obsws.set_stream_service_settings(
'rtmp_common',
{
'service': 'Twitch',
'server': 'auto',
'key': os.environ['OBS_STREAM_KEY'],
},
)
session.obsws.set_current_scene_collection('test-collection')
session.obsws.create_scene('pytest')
session.obsws.create_input(
sceneName='pytest',
inputName='pytest_input',
inputKind='color_source_v3',
inputSettings={
'color': 3279460728,
'width': 1920,
'height': 1080,
'visible': True,
},
sceneItemEnabled=True,
)
session.obsws.create_input(
sceneName='pytest',
inputName='pytest_input_2',
inputKind='color_source_v3',
inputSettings={
'color': 1789347616,
'width': 720,
'height': 480,
'visible': True,
},
sceneItemEnabled=True,
)
resp = session.obsws.get_scene_item_list('pytest')
for item in resp.scene_items:
if item['sourceName'] == 'pytest_input_2':
session.obsws.set_scene_item_transform(
'pytest',
item['sceneItemId'],
{
'rotation': 0,
},
)
break
def pytest_sessionfinish(session, exitstatus):
"""Call after the whole test run finishes.
Return the exit status to the system.
"""
session.obsws.remove_scene('pytest')
resp = session.obsws.get_stream_status()
if resp.output_active:
session.obsws.stop_stream()
# Close the OBS WebSocket client connection
session.obsws.disconnect()
def pytest_unconfigure(config):
"""Call before test process is exited."""