-
-
Save alrocar/ae42cd9c57e83ef861ee99cc232e93cf to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import os | |
import datetime | |
import requests | |
import orjson | |
def pytest_terminal_summary(terminalreporter, exitstatus, config): | |
token = os.environ.get('TINYBIRD_TOKEN') | |
commit = os.environ.get('CI_COMMIT_SHA') | |
job_id = os.environ.get('CI_JOB_ID') | |
if not commit or not job_id: | |
# Only get metrics about CI | |
return | |
now = str(datetime.datetime.now()) | |
report = [] | |
for k in terminalreporter.stats: | |
for test in terminalreporter.stats[k]: | |
try: | |
report.append({ | |
'date': now, | |
'commit': commit, | |
'job_id': job_id, | |
'job_url': os.environ.get('CI_JOB_URL', ''), | |
'job_name': os.environ.get('CI_JOB_NAME', ''), | |
'test_nodeid': test.nodeid, | |
'test_name': test.head_line, | |
'test_part': test.when, | |
'duration': test.duration, | |
'outcome': test.outcome | |
}) | |
except Exception: | |
pass | |
data = b'\n'.join(orjson.dumps(x) for x in report) | |
response = requests.post(f'https://api.tinybird.co/v0/events?name=ci_tests&token={token}', data=data) | |
if response.status_code != 202: | |
print("Error while uploading to tinybird") |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment