Skip to content

Commit

Permalink
ci: Add a server to track flakyness in pytest tests
Browse files Browse the repository at this point in the history
  • Loading branch information
cdecker committed Aug 27, 2023
1 parent f710676 commit 3582976
Show file tree
Hide file tree
Showing 2 changed files with 61 additions and 0 deletions.
1 change: 1 addition & 0 deletions .github/workflows/ci.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ env:
# of a bit of compile time.
RUST_PROFILE: release
SLOW_MACHINE: 1
CI_SERVER: "http://35.239.136.52:3170"

jobs:
prebuild:
Expand Down
60 changes: 60 additions & 0 deletions conftest.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
import pytest
import subprocess
import urllib3
import os
import json
from time import time

server = os.environ.get("CI_SERVER", None)

github_sha = subprocess.check_output([
"git",
"rev-parse",
"HEAD"
]).decode('ASCII').strip()

github_ref_name = subprocess.check_output([
"git",
"rev-parse",
"--abbrev-ref",
"HEAD"
]).decode('ASCII').strip()

result = {
"github_sha": os.environ.get("GITHUB_SHA", github_sha),
"github_ref": os.environ.get("GITHUB_REF", None),
"github_ref_name": os.environ.get("GITHUB_REF_NAME", github_ref_name),
}


@pytest.hookimpl(hookwrapper=True)
def pytest_pyfunc_call(pyfuncitem):
global result
result = result.copy()
result['testname'] = pyfuncitem.name
result['start_time'] = int(time())
outcome = yield
result['end_time'] = int(time())
# outcome.excinfo may be None or a (cls, val, tb) tuple

if outcome.excinfo is None:
result['outcome'] = "success"
else:
result['outcome'] = "fail"

print(result)

if not server:
return

try:
urllib3.request(
method="POST",
url=f"{server}/hook/test",
body=json.dumps(result),
headers={
"Content-Type": "application/json",
},
)
except Exception as e:
print(f"Could not report testrun: {e}")

0 comments on commit 3582976

Please sign in to comment.