-
Notifications
You must be signed in to change notification settings - Fork 16.4k
Fixes #57515 - Fix test_async_write_logs_should_execute_successfully test #58276
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Fixes #57515 - Fix test_async_write_logs_should_execute_successfully test #58276
Conversation
- Add client mock patch to properly mock self.client.read_namespaced_pod_log - Fix assertions to verify actual log output using caplog - Fix get_logs=False assertion to check client.read_namespaced_pod_log instead of pod_manager.read_pod_logs - Add await_pod_completion mock return value Fixes apache#57515
providers/cncf/kubernetes/tests/unit/cncf/kubernetes/operators/test_pod.py
Outdated
Show resolved
Hide resolved
- Remove @pytest.mark.xfail decorator as the test is now fixed - Remove incorrect assertion checking mock_manager.read_pod_logs which is never called by _write_logs() (it calls client.read_namespaced_pod_log directly instead) Both parameterized test cases now pass: - test_async_write_logs_should_execute_successfully[True] ✅ - test_async_write_logs_should_execute_successfully[False] ✅ Addresses reviewer feedback to remove xfail flag as proof the test works.
|
FInally now some static checks fail - can you run our pre-commit checks via |
- Remove unused imports: BytesIO and HTTPResponse - Format function parameters on multiple lines for better readability
Applied ruff formatting fixes: removed unused imports and formatted function parameters. All prek checks pass. Thanks! |
jscheffl
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks good! LGTM when CI turns green!
…fully test (apache#58276) * Fix test_async_write_logs_should_execute_successfully test - Add client mock patch to properly mock self.client.read_namespaced_pod_log - Fix assertions to verify actual log output using caplog - Fix get_logs=False assertion to check client.read_namespaced_pod_log instead of pod_manager.read_pod_logs - Add await_pod_completion mock return value Fixes apache#57515 * Remove @pytest.mark.xfail and fix incorrect assertion - Remove @pytest.mark.xfail decorator as the test is now fixed - Remove incorrect assertion checking mock_manager.read_pod_logs which is never called by _write_logs() (it calls client.read_namespaced_pod_log directly instead) Both parameterized test cases now pass: - test_async_write_logs_should_execute_successfully[True] ✅ - test_async_write_logs_should_execute_successfully[False] ✅ Addresses reviewer feedback to remove xfail flag as proof the test works. * Apply ruff formatting fixes - Remove unused imports: BytesIO and HTTPResponse - Format function parameters on multiple lines for better readability
…fully test (apache#58276) * Fix test_async_write_logs_should_execute_successfully test - Add client mock patch to properly mock self.client.read_namespaced_pod_log - Fix assertions to verify actual log output using caplog - Fix get_logs=False assertion to check client.read_namespaced_pod_log instead of pod_manager.read_pod_logs - Add await_pod_completion mock return value Fixes apache#57515 * Remove @pytest.mark.xfail and fix incorrect assertion - Remove @pytest.mark.xfail decorator as the test is now fixed - Remove incorrect assertion checking mock_manager.read_pod_logs which is never called by _write_logs() (it calls client.read_namespaced_pod_log directly instead) Both parameterized test cases now pass: - test_async_write_logs_should_execute_successfully[True] ✅ - test_async_write_logs_should_execute_successfully[False] ✅ Addresses reviewer feedback to remove xfail flag as proof the test works. * Apply ruff formatting fixes - Remove unused imports: BytesIO and HTTPResponse - Format function parameters on multiple lines for better readability
…fully test (apache#58276) * Fix test_async_write_logs_should_execute_successfully test - Add client mock patch to properly mock self.client.read_namespaced_pod_log - Fix assertions to verify actual log output using caplog - Fix get_logs=False assertion to check client.read_namespaced_pod_log instead of pod_manager.read_pod_logs - Add await_pod_completion mock return value Fixes apache#57515 * Remove @pytest.mark.xfail and fix incorrect assertion - Remove @pytest.mark.xfail decorator as the test is now fixed - Remove incorrect assertion checking mock_manager.read_pod_logs which is never called by _write_logs() (it calls client.read_namespaced_pod_log directly instead) Both parameterized test cases now pass: - test_async_write_logs_should_execute_successfully[True] ✅ - test_async_write_logs_should_execute_successfully[False] ✅ Addresses reviewer feedback to remove xfail flag as proof the test works. * Apply ruff formatting fixes - Remove unused imports: BytesIO and HTTPResponse - Format function parameters on multiple lines for better readability
Description
This PR fixes the broken test
test_async_write_logs_should_execute_successfully()in the KubernetesPodOperator test suite. The test was incorrectly implemented and was not properly testing the async log writing functionality.Changes
@patch(KUB_OP_PATH.format("client"))decorator to properly mockself.client.read_namespaced_pod_log()which is the actual method used by_write_logs()mocked_client.read_namespaced_pod_loginstead of incorrectly mockingmock_manager.read_pod_logs(which is never called)[test_logs.encode("utf-8")]as expected by the implementationmock_manager.await_pod_completion.return_valuefor proper test flowcaploginstead of a meaningless string assertionget_logs=Falseassertion to checkmocked_client.read_namespaced_pod_log.assert_not_called()instead of the incorrectpod_manager.read_pod_logscheckRoot Cause
The test had three main issues:
pod_manager.read_pod_logsbut_write_logs()actually callsself.client.read_namespaced_pod_log()directlyassert f"Container logs: {test_logs}"always passes (it's just checking if a string exists, not if it was logged)pod_manager.read_pod_logswhich is never called by_write_logs()Testing
test_async_write_logs_should_execute_successfully[True]✅test_async_write_logs_should_execute_successfully[False]✅Type of Change
Fixes #57515