GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — gh-127747: Resolve BytesWarning in test.support.strace_helper by cmaloney · Pull Request #127849 · python/cpython

Conversation

@cmaloney

@cmaloney cmaloney commented Dec 12, 2024 •
edited by bedevere-app Bot
Loading

Uh oh!

There was an error while loading. Please reload this page.

Copy link
Copy Markdown
Contributor

Validation Steps:

  1. Update Lib/test/support/strace_helper.py to set _strace_binary to /usr/bin/false (or don't have strace installed)
  2. Run ./python -Werror -I -bb -m test.test_subprocess -vv POSIXProcessTestCase.test_vfork_used_when_expected

Description

The strace_helper code has a _make_error function to simplify making StraceResult objects in error cases. That takes a details parameter which is either a caught OSError or bytes. If it's bytes, _make_error would implicitly coerce that to a str inside of a f-string, resulting in a BytesWarning when the python test is invoked with -b.

It is useful to distinguish between an OSError or bytes when debugging the test, so eliminate the BytesWarning and show both by changing to format with repr().

After fixing the implicing bytes-> str conversion, if /usr/bin/strace is uninstalled/doesn't exist, get a new error running the test:

  File "<source_dir>/cpython/Lib/test/support/strace_helper.py", line 183, in _can_strace
    assert res.events(), "Should have parsed multiple calls"
           ~~~~~~~~~~^^
AssertionError: Should have parsed multiple calls

Resolved by checking the exit code of the subprocess before asserting there should be events. Reason for asserting there are events, rather than returning False from _can_strace, is to try and ensure that if strace runs successfully and produces an output that can't be parsed that is a test error rather than silently disabling all strace tests (See: gh-121381 where a feature working was tested with strace but the strace tests stopped running, leading to this infrastructure in #123413).

skip news: This is a fix to an error message on a python test suite internal helper.

  • Issue: Unhandled BytesWarning when test.support.strace_helper.strace_python fails #127747

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions
cmaloney added 2 commits December 11, 2024 18:04
@cmaloney
pythongh-127747: Use repr to normalize in strace_helper
7d02313
The strace_helper code has a _make_error function to simplify making
StraceResult objects in error cases. That takes a details parameter
which is either a caught OSError or `bytes`. If it's bytes, _make_error
would implicitly coerce that to a str inside of a f-string, resulting in
 a BytesWarning.

It's useful to see if it's an OSError or bytes when debugging, resolve
by changing to format with repr().

This is an error message on an internal helper.
@cmaloney
pythongh-127747: Fix w/o strace and with -Werror
9bf31a6
A non-zero exit code occurs if the strace binary isn't found, and no
events will be parsed in that case (there is no output). Handle that
case by checking exit code before checking for events.

Still asserting around events rather than returning false, so that
hopefully if there's some change to `strace` that breaks the parsing,
will see that as a test failure rather than silently loosing strace
tests because they are auto-disabled.
@bedevere-app bedevere-app Bot mentioned this pull request Dec 12, 2024
Unhandled BytesWarning when test.support.strace_helper.strace_python fails #127747
Closed
@bedevere-app bedevere-app Bot added the awaiting review label Dec 12, 2024
@skirpichev skirpichev added tests Tests in the Lib/test dir skip news labels Dec 12, 2024
ZeroIntensity
ZeroIntensity reviewed Dec 12, 2024
View reviewed changes
Comment thread Lib/test/support/strace_helper.py Resolved

Uh oh!

There was an error while loading. Please reload this page.

@cmaloney
Review fixes
e83dbfb
ZeroIntensity
ZeroIntensity approved these changes Dec 13, 2024
View reviewed changes

@ZeroIntensity ZeroIntensity left a comment

Copy link
Copy Markdown
Member

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.

Thanks!

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

cmaloney reacted with thumbs up emoji
All reactions
  • 👍 1 reaction
@bedevere-app bedevere-app Bot added awaiting core review and removed awaiting review labels Dec 13, 2024
hauntsaninja
hauntsaninja approved these changes Dec 14, 2024
View reviewed changes

@hauntsaninja hauntsaninja left a comment

Copy link
Copy Markdown
Contributor

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.

Thank you!

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

cmaloney reacted with thumbs up emoji
All reactions
  • 👍 1 reaction
@bedevere-app bedevere-app Bot added awaiting merge and removed awaiting core review labels Dec 14, 2024
@hauntsaninja
hauntsaninja merged commit c0264fc into python:main Dec 14, 2024
@bedevere-app bedevere-app Bot removed the awaiting merge label Dec 14, 2024
@cmaloney
cmaloney deleted the cmaloney/strace_warning branch December 16, 2024 02:56
srinivasreddy pushed a commit to srinivasreddy/cpython that referenced this pull request Jan 8, 2025
@cmaloney @srinivasreddy
pythongh-127747: Resolve BytesWarning in test.support.strace_helper (p…
828461a
…ython#127849)

The strace_helper code has a _make_error function to simplify making
StraceResult objects in error cases. That takes a details parameter
which is either a caught OSError or `bytes`. If it's bytes, _make_error
would implicitly coerce that to a str inside of a f-string, resulting in
 a BytesWarning.

It's useful to see if it's an OSError or bytes when debugging, resolve
by changing to format with repr().

This is an error message on an internal helper.

A non-zero exit code occurs if the strace binary isn't found, and no
events will be parsed in that case (there is no output). Handle that
case by checking exit code before checking for events.

Still asserting around events rather than returning false, so that
hopefully if there's some change to `strace` that breaks the parsing,
will see that as a test failure rather than silently loosing strace
tests because they are auto-disabled.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Reviewers

@hauntsaninja hauntsaninja hauntsaninja approved these changes
@ZeroIntensity ZeroIntensity ZeroIntensity approved these changes

Uh oh!

There was an error while loading. Please reload this page.

Assignees

No one assigned

Labels

skip news tests Tests in the Lib/test dir

Projects

None yet

Milestone

No milestone

Development

Successfully merging this pull request may close these issues.

Uh oh!

There was an error while loading. Please reload this page.

4 participants

@cmaloney @hauntsaninja @ZeroIntensity @skirpichev
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
You are visitor 01402520 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.