Skip to content

Fix Failing UT#347

Open
yashnap wants to merge 1 commit into
masterfrom
UT_fix
Open

Fix Failing UT#347
yashnap wants to merge 1 commit into
masterfrom
UT_fix

Conversation

@yashnap
Copy link
Copy Markdown
Contributor

@yashnap yashnap commented May 21, 2026

  • Fix failing UT

Why it Failed in Pycharm:
The test failed in PyCharm because PyCharm uses a custom unittest runner that wraps and manages sys.stdout for output capture. This conflicts with manual reassignment of sys.stdout, causing it to be replaced at runtime with a _io.TextIOWrapper that does not support getvalue(), leading to an AttributeError.

Why it passed in PR (CI) ( My assumption/Copilot Suggestion)
The test passed in the PR pipeline because it was executed using the standard Python unittest runner (python -m unittest), which does not override or wrap sys.stdout. As a result, the manual reassignment sys.stdout = StringIO() remained intact, and the captured output could be read correctly using getvalue()

The failure is due to a conflict between manual sys.stdout reassignment and PyCharm’s test runner, which overrides stdout handling, while CI uses the standard unittest runner without such interference.

-Since we will be making changes to the PackageManager code to remove this behavior and actually return a package manager value, this can be used as temporary workaround

Copilot AI review requested due to automatic review settings May 21, 2026 16:18
@codecov
Copy link
Copy Markdown

codecov Bot commented May 21, 2026

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 93.83%. Comparing base (6f0af88) to head (9303749).

Additional details and impacted files
@@            Coverage Diff             @@
##           master     #347      +/-   ##
==========================================
- Coverage   93.84%   93.83%   -0.01%     
==========================================
  Files         105      105              
  Lines       18218    18214       -4     
==========================================
- Hits        17096    17092       -4     
  Misses       1122     1122              
Flag Coverage Δ
python27 93.83% <100.00%> (-0.01%) ⬇️
python312 93.79% <100.00%> (-0.05%) ⬇️

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ 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
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

This PR updates the EnvLayer.get_package_manager() unit test for Azure Linux 4 and RHEL 10 “unsupported” scenarios, aiming to address a test failure caused by stdout capture differences between PyCharm’s runner and CI.

Changes:

  • Removed manual sys.stdout reassignment / StringIO capture in test_get_package_manager_azure_linux_4_and_rhel10_not_supported.
  • Simplified assertions to only validate the empty-string return value from get_package_manager() for unsupported distros.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment on lines 167 to +171
for row in test_input_output_table:
self.envlayer.platform.linux_distribution = row[0]
distro.os_release_attr = row[1]

captured_output = io.StringIO()
sys.stdout = captured_output
result = self.envlayer.get_package_manager()
sys.stdout = sys.__stdout__
self.assertEqual(row[2], captured_output.getvalue())
self.assertEqual(result, "")
package_manager = self.envlayer.get_package_manager()
self.assertEqual(package_manager, "")
@kjohn-msft kjohn-msft added bug Something isn't working OE PR is considered near complete due to OE sign-off. labels May 22, 2026
captured_output = io.StringIO()
sys.stdout = captured_output
result = self.envlayer.get_package_manager()
sys.stdout = sys.__stdout__
Copy link
Copy Markdown
Contributor

@rane-rajasi rane-rajasi May 22, 2026

Choose a reason for hiding this comment

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

@yashnap, I think the problem was this line. See other examples in code where this is already implemented, for eg: test_reset_auto_assessment_log_file_if_needed_raise_exception()

you are setting sys.stdout to captured_output on line 171, but on line 174 while resetting sys.stdout it is set to "sys.__ stdout __ " (adding space because of github formatting). What does sys.__ stdout __ represent? Why not reset it to its original value?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug Something isn't working OE PR is considered near complete due to OE sign-off.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants