twitch-chat-bot
twitch-chat-bot copied to clipboard
when tests fail in pytest, post to chat
idk quite how this would work, but here's an idea:
- start some sort of web socket / server in bot
- change
pytestto be an alias - somehow grep output for failures (or install a pytest plugin? idk)
Could you alias a command like pt to a pyteset_alias.py file
pytest_alias.py
import sys
import os
args = sys.argv[1:]
os.system(f'pytest {" ".join([a for a in args])}')
and then call bot functions from within conftest.py?
import pytest
def pytest_sessionstart(session):
session.results = {}
@pytest.hookimpl(tryfirst=True, hookwrapper=True)
def pytest_runtest_makereport(item):
outcome = yield
result = outcome.get_result()
if result.when == "call":
item.session.results[item] = result
def pytest_sessionfinish(session):
if sum(1 for result in session.results.values() if result.failed) > 0:
do_bot_stuff()
def do_bot_stuff():
print("bot goes brrr")
This is working for me, I get
FAILED bot goes brrr
after typing this in the terminal
python pytest_alias.py -sv tests/test_alias.py
I think the tricky part is pytest is usually in the project's virtualenv and not the bot's virtualenv so the injection needs to be super generic (can't really overwrite the project's conftest.py for example)