Skip to content

chore: Fix Console output when running on Top Level Statements #835

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

Merged
merged 5 commits into from
Apr 8, 2025

Conversation

hjgraca
Copy link
Contributor

@hjgraca hjgraca commented Apr 7, 2025

Please provide the issue number

Issue number: #783

Summary

Changes

This pull request introduces changes to the SystemWrapper class to support test mode functionality and adds corresponding unit tests. The most important changes include adding test mode fields, modifying the logging methods to handle test mode, and adding new private methods to manage console output. Additionally, new unit tests are added to verify the behavior in both production and test modes.

Changes to SystemWrapper class:

  • Added _inTestMode, _testOutputStream, and _outputResetPerformed fields to support test mode and track console output state.
  • Modified the constructor to conditionally reset console output based on the test mode flag.
  • Updated Log and LogLine methods to write to _testOutputStream in test mode and ensure console output is reset once in production mode.
  • Added SetOut method to enable test mode by setting _testOutputStream and _inTestMode flag.
  • Introduced EnsureConsoleOutputOnce, ResetConsoleOutput, ClearOutputResetFlag, and ResetTestMode methods to manage console output and test mode state.

New unit tests:

  • Added SystemWrapperTests class with tests to verify logging behavior in both production and test modes, and to ensure proper state management of console output.

User experience

Please share what the user experience looks like before and after this change

Checklist

Please leave checklist items unchecked if they do not apply to your change.

Is this a breaking change?

RFC issue number:

Checklist:

  • Migration process documented
  • Implement warnings (if it can live side by side)

Acknowledgment

By submitting this pull request, I confirm that you can use, modify, copy, and redistribute this contribution, under the terms of your choice.

Disclaimer: We value your time and bandwidth. As such, any pull requests created on non-triaged issues might not be successful.

@boring-cyborg boring-cyborg bot added area/common Core Powertools utility tests labels Apr 7, 2025
@pull-request-size pull-request-size bot added the size/L Denotes a PR that changes 100-499 lines, ignoring generated files. label Apr 7, 2025
@hjgraca hjgraca linked an issue Apr 7, 2025 that may be closed by this pull request
@github-actions github-actions bot added the internal Maintenance changes label Apr 7, 2025
Copy link

codecov bot commented Apr 7, 2025

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 74.32%. Comparing base (6d5a12c) to head (af3419e).
Report is 6 commits behind head on develop.

Additional details and impacted files
@@             Coverage Diff             @@
##           develop     #835      +/-   ##
===========================================
+ Coverage    74.18%   74.32%   +0.13%     
===========================================
  Files          211      211              
  Lines         8430     8464      +34     
  Branches       914      918       +4     
===========================================
+ Hits          6254     6291      +37     
+ Misses        1883     1880       -3     
  Partials       293      293              

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

Copy link

sonarqubecloud bot commented Apr 8, 2025

@hjgraca hjgraca merged commit 8b6d925 into aws-powertools:develop Apr 8, 2025
9 checks passed
@hjgraca hjgraca deleted the fix/override-lambda-console branch April 8, 2025 09:05
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area/common Core Powertools utility internal Maintenance changes size/L Denotes a PR that changes 100-499 lines, ignoring generated files. tests
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Bug: CloudWatch logs do not use same logging level as PowerTools
2 participants