Skip to content
This repository has been archived by the owner on Sep 1, 2024. It is now read-only.

Commit

Permalink
Replace TestSuiteRunSummary with TestSuiteRunPendingSummary
Browse files Browse the repository at this point in the history
  • Loading branch information
ramosbugs committed Sep 18, 2022
1 parent 6d8b413 commit a31066e
Show file tree
Hide file tree
Showing 4 changed files with 7 additions and 44 deletions.
2 changes: 1 addition & 1 deletion setup.cfg
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[metadata]
name = pytest-unflakable
version = 0.1.2
version = 0.1.3
author = Unflakable
author_email = [email protected]
maintainer = Unflakable
Expand Down
13 changes: 3 additions & 10 deletions src/pytest_unflakable/_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -70,18 +70,11 @@ class CreateTestSuiteRunRequest(TypedDict):
test_runs: List[TestRunRecord]


class TestSuiteRunSummary(TypedDict):
class TestSuiteRunPendingSummary(TypedDict):
run_id: str
suite_id: str
branch: NotRequired[Optional[str]]
commit: NotRequired[Optional[str]]
start_time: str
end_time: str
num_tests: int
num_pass: int
num_fail: int
num_flake: int
num_quarantined: int


def create_test_suite_run(
Expand All @@ -91,7 +84,7 @@ def create_test_suite_run(
base_url: Optional[str],
insecure_disable_tls_validation: bool,
logger: logging.Logger,
) -> TestSuiteRunSummary:
) -> TestSuiteRunPendingSummary:
logger.debug(f'creating test suite run {pprint.pformat(request)}')

run_response = requests.post(
Expand All @@ -109,7 +102,7 @@ def create_test_suite_run(
)
run_response.raise_for_status()

summary: TestSuiteRunSummary = run_response.json()
summary: TestSuiteRunPendingSummary = run_response.json()
logger.debug(f'received response: {pprint.pformat(summary)}')

return summary
Expand Down
32 changes: 1 addition & 31 deletions tests/common.py
Original file line number Diff line number Diff line change
Expand Up @@ -229,29 +229,13 @@ def mock_run(
def mock_create_test_suite_run_response(
request: requests.Request,
context: requests_mock.response._Context,
) -> _api.TestSuiteRunSummary:
) -> _api.TestSuiteRunPendingSummary:
request_body: _api.CreateTestSuiteRunRequest = request.json()
return {
'run_id': MOCK_RUN_ID,
'suite_id': MOCK_SUITE_ID,
'branch': request_body.get('branch'),
'commit': request_body.get('commit'),
'start_time': request_body['start_time'],
'end_time': request_body['end_time'],
'num_tests': len(request_body['test_runs']),
'num_pass': len(
[run for run in request_body['test_runs'] if
all([attempt['result'] == 'pass' for attempt in run['attempts']])]),
'num_fail': len(
[run for run in request_body['test_runs'] if
all([attempt['result'] == 'fail' for attempt in run['attempts']])]),
'num_flake': len(
[run for run in request_body['test_runs'] if
any([attempt['result'] == 'pass' for attempt in run['attempts']]) and any(
[attempt['result'] == 'fail' for attempt in run['attempts']])]),
'num_quarantined': len(
[run for run in request_body['test_runs'] if
all([attempt['result'] == 'quarantined' for attempt in run['attempts']])]),
}


Expand Down Expand Up @@ -524,20 +508,6 @@ def run_test_case(
create_test_suite_run_request.json()
)

assert_regex(TIMESTAMP_REGEX, create_test_suite_run_body['start_time'])
assert_regex(TIMESTAMP_REGEX, create_test_suite_run_body['end_time'])

actual_test_runs = {
(test_run_record['filename'], tuple(test_run_record['name'])): [
attempt['result'] for attempt in test_run_record['attempts']
]
for test_run_record in create_test_suite_run_body['test_runs']
}
assert actual_test_runs == expected_uploaded_test_runs

# Make sure there aren't any duplicate test keys.
assert len(create_test_suite_run_body['test_runs']) == len(actual_test_runs)

if expected_commit is not None:
assert create_test_suite_run_body['commit'] == expected_commit
else:
Expand Down
4 changes: 2 additions & 2 deletions tests/test_unflakable.py
Original file line number Diff line number Diff line change
Expand Up @@ -1216,8 +1216,8 @@ def test_pass():
expected_commit='CLI_COMMIT',
expect_xdist=xdist,
extra_args=[
'--branch', 'CLI_BRANCH', '--commit', 'CLI_COMMIT'
] + (XDIST_ARGS if xdist else []),
'--branch', 'CLI_BRANCH', '--commit', 'CLI_COMMIT'
] + (XDIST_ARGS if xdist else []),
)


Expand Down

0 comments on commit a31066e

Please sign in to comment.