Skip to content

python(feat): Add optional logging of test result create and update e…#529

Merged
ian-sift merged 11 commits into
mainfrom
test-result-delayed-upload
Apr 13, 2026
Merged

python(feat): Add optional logging of test result create and update e…#529
ian-sift merged 11 commits into
mainfrom
test-result-delayed-upload

Conversation

@ian-sift
Copy link
Copy Markdown
Contributor

@ian-sift ian-sift commented Apr 8, 2026

Add optional logging of test result create and update events that, when used, defer calls to Sift to the end of the test where the log is then replayed and uploaded.

Design:

  • Add optional log_file args to update and create methods in test_results
    • When true, logs requests to file and calls new simulate methods that mock the create/update that the backend would do
  • Add a replay function that reads the logs and first plays them back in memory to consolidate intermediate update calls before calling create on the resultant report, steps, and measurements
  • Plumb the ability for the test result context manager helper to optionally create a log file and replay the result at the of the report context
  • update pytest fixtures to tell the context manager to use logging

Verification

  • Updated test results integrated tests to run create & update calls first w/ logs and then compare results
  • Ran w/ + without logging
  • Tested throwing an error when replaying and ensuring context manager prints command to retry upload and verified that command runs successfully

Example snippet from a log:


[CreateTestReport:c963ee35-10af-494b-886a-1241bc88e5a1] {"status":"TEST_STATUS_IN_PROGRESS","name":"pytest --log-cli-level=INFO -s /Users/ian/code/sift/python/lib/sift_client/_tests/resources/ 2026-04-09T00:14:38.904637+00:00","testSystemName":"Mac.attlocal.net","testCase":"pytest --log-cli-level=INFO -s /Users/ian/code/sift/python/lib/sift_client/_tests/resources/","startTime":"2026-04-09T00:14:38.905452Z","endTime":"2026-04-09T00:14:38.905453Z","systemOperator":"ian"}
[CreateTestStep:8914bbad-b802-44fa-b55a-033cbc1f4fc9] {"testStep":{"testReportId":"c963ee35-10af-494b-886a-1241bc88e5a1","name":"test_assets.py","description":"Pytest tests for the Assets API.\n\nThese tests demonstrate and validate the usage of the Assets API including:\n- Basic asset operations (get, list, find)\n- Asset filtering and searching\n- Asset updates and archiving\n- Error handling and edge cases\n","stepType":"TEST_STEP_TYPE_ACTION","stepPath":"1","status":"TEST_STATUS_IN_PROGRESS","startTime":"2026-04-09T00:14:38.906178Z","endTime":"2026-04-09T00:14:38.906178Z"}}
[CreateTestStep:fead8af8-7634-40f1-a29a-d963c0e163cd] {"testStep":{"testReportId":"c963ee35-10af-494b-886a-1241bc88e5a1","parentStepId":"8914bbad-b802-44fa-b55a-033cbc1f4fc9","name":"test_client_binding","stepType":"TEST_STEP_TYPE_ACTION","stepPath":"1.1","status":"TEST_STATUS_IN_PROGRESS","startTime":"2026-04-09T00:14:38.907785Z","endTime":"2026-04-09T00:14:38.907788Z"}}
[UpdateTestStep] {"testStep":{"testStepId":"fead8af8-7634-40f1-a29a-d963c0e163cd","status":"TEST_STATUS_PASSED","endTime":"2026-04-09T00:14:38.908571Z"},"updateMask":"status,endTime"}
[CreateTestStep:1d557fe5-6d1a-4ae9-b514-54137512633a] {"testStep":{"testReportId":"c963ee35-10af-494b-886a-1241bc88e5a1","parentStepId":"8914bbad-b802-44fa-b55a-033cbc1f4fc9","name":"test_basic_list","description":"Test basic asset listing functionality.","stepType":"TEST_STEP_TYPE_ACTION","stepPath":"1.2","status":"TEST_STATUS_IN_PROGRESS","startTime":"2026-04-09T00:14:38.910027Z","endTime":"2026-04-09T00:14:38.910028Z"}}
[UpdateTestStep] {"testStep":{"testStepId":"1d557fe5-6d1a-4ae9-b514-54137512633a","status":"TEST_STATUS_PASSED","endTime":"2026-04-09T00:14:38.919790Z"},"updateMask":"status,endTime"}
[CreateTestStep:1736ca2b-1de8-4978-99d3-6f012c299386] {"testStep":{"testReportId":"c963ee35-10af-494b-886a-1241bc88e5a1","parentStepId":"8914bbad-b802-44fa-b55a-033cbc1f4fc9","name":"test_list_with_name_filter","description":"Test asset listing with name filtering.","stepType":"TEST_STEP_TYPE_ACTION","stepPath":"1.3","status":"TEST_STATUS_IN_PROGRESS","startTime":"2026-04-09T00:14:38.921397Z","endTime":"2026-04-09T00:14:38.921398Z"}}
[UpdateTestStep] {"testStep":{"testStepId":"1736ca2b-1de8-4978-99d3-6f012c299386","status":"TEST_STATUS_PASSED","endTime":"2026-04-09T00:14:38.932600Z"},"updateMask":"status,endTime"}
[CreateTestStep:2c0e3763-e4be-4ca8-8af5-4ca562e77142] {"testStep":{"testReportId":"c963ee35-10af-494b-886a-1241bc88e5a1","parentStepId":"8914bbad-b802-44fa-b55a-033cbc1f4fc9","name":"test_list_with_name_contains_filter","description":"Test asset listing with name contains filtering.","stepType":"TEST_STEP_TYPE_ACTION","stepPath":"1.4","status":"TEST_STATUS_IN_PROGRESS","startTime":"2026-04-09T00:14:38.933473Z","endTime":"2026-04-09T00:14:38.933475Z"}}
[UpdateTestStep] {"testStep":{"testStepId":"2c0e3763-e4be-4ca8-8af5-4ca562e77142","status":"TEST_STATUS_PASSED","endTime":"2026-04-09T00:14:38.937887Z"},"updateMask":"status,endTime"}
[CreateTestStep:2dbeff75-6389-4afd-8886-345687dfb04f] {"testStep":{"testReportId":"c963ee35-10af-494b-886a-1241bc88e5a1","parentStepId":"8914bbad-b802-44fa-b55a-033cbc1f4fc9","name":"test_list_with_limit","description":"Test asset listing with different limits.","stepType":"TEST_STEP_TYPE_ACTION","stepPath":"1.5","status":"TEST_STATUS_IN_PROGRESS","startTime":"2026-04-09T00:14:38.938600Z","endTime":"2026-04-09T00:14:38.938602Z"}}
[UpdateTestStep] {"testStep":{"testStepId":"2dbeff75-6389-4afd-8886-345687dfb04f","status":"TEST_STATUS_PASSED","endTime":"2026-04-09T00:14:38.949853Z"},"updateMask":"status,endTime"}

Note: A ~250 step test runs ~1s faster w/ logging than hitting API during run

…vents that, when used, defer calls to Sift to the end of the test where the log is then replayed and uploaded.
@ian-sift ian-sift requested a review from alexluck-sift April 8, 2026 23:31
Comment thread python/lib/sift_client/util/test_results/context_manager.py Fixed
@ian-sift ian-sift removed the request for review from alexluck-sift April 8, 2026 23:32
Comment thread python/lib/google/__init__.py Outdated
Comment thread python/lib/sift_client/util/test_results/context_manager.py
Comment thread python/lib/sift_client/util/test_results/context_manager.py Outdated
Comment thread python/lib/sift_client/util/test_results/context_manager.py Outdated
Comment thread python/lib/sift_client/util/test_results/context_manager.py
Comment thread python/lib/sift_client/scripts/replay_test_result_log.py Outdated
Comment thread python/lib/sift_client/resources/test_results.py Outdated
Comment thread python/lib/sift_client/_internal/low_level_wrappers/test_results.py
Comment thread python/lib/sift_client/_tests/resources/test_test_results.py Outdated
Comment thread python/lib/sift_client/_internal/low_level_wrappers/test_results.py
Comment thread python/lib/sift_client/_internal/low_level_wrappers/test_results.py
Comment thread python/lib/sift_client/_internal/low_level_wrappers/test_results.py
Comment thread python/lib/sift_client/_internal/low_level_wrappers/test_results.py
Comment thread python/lib/sift_client/_internal/low_level_wrappers/test_results.py Outdated
Comment thread python/lib/sift_client/_internal/low_level_wrappers/test_results.py Outdated
Comment thread python/lib/sift_client/_internal/low_level_wrappers/test_results.py
Comment thread python/lib/sift_client/_internal/low_level_wrappers/test_results.py
@ian-sift ian-sift enabled auto-merge (squash) April 13, 2026 18:20
Copy link
Copy Markdown
Collaborator

@alexluck-sift alexluck-sift left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

lgtm!

@ian-sift ian-sift merged commit b70b6e3 into main Apr 13, 2026
23 of 25 checks passed
@ian-sift ian-sift deleted the test-result-delayed-upload branch April 13, 2026 18:23
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants