Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Update tests to use test.support.captured_std* #136632

Open
Labels
testsTests in the Lib/test dirtype-refactorCode refactoring (with no changes in behavior)
@inventshah

Description

@inventshah

Python's test suite hastest.support.captured_std* utilities to temporarily swapsys.std* with anio.StringIO(). These wrapper functions are used at least 240 times throughout the tests. A few greps1 show quite a few instances where these helpers could be used but are not (45 usecontextlib.redirect_std*, 30 usetest.support.captured_output("std*"), and 15 use a manual solution).

Should we update these calls to use thesupport utilities to improve consistency or is it not worth the risk of accidentally changing a test's meaning and cluttering git blame? I found31d1d72 from last year which did similar updating intest_pydoc/test_pydoc.py. There's also an argument the "update" should go fromtest.support.captured_std* to the newercontextlib.redirect_std* instead, and remove the testing specific utilities.

Since this touches a wide range of domains, my thought was to split this up into separate PRs for each test file so the appropriate person can more easily review. But we can also do this in larger chunks, at least for the lower risk changes.

Instances ofcontextlib.redirect_std* swappable fortest.support.captured_std*. In some cases allowing the removal ofio andcontextlib imports.

Instances oftest.support.captured_output("std*") swappable for a correspondingtest.support.captured_std*. Low risk to change since the latter calls the former.

Tests with a manual stream save/restore (most are stdin). Higher risk especially when replacing over long blocks.

  • libregrtest/single.py -L297
  • test_builtin.py -L1748
  • test_capi/check_config.py -L70
  • test_concurrent_futures/test_deadlock.py -L148
  • test_exceptions.py -L71
  • test_faulthandler.py -L399,L806
  • test_fileinput.py -L129,L151
  • test_optparse.py -L160
  • test_profile.py -L90 &L101 callsilent which could betest.support.captured_stdout instead of reimplementing the function.
  • test_pydoc.py -L478
  • test_unittest/test_runner.py -L1425
  • test_winconsoleio.py -L170
  • test_wsgiref.py -L74

Linked PRs

Footnotes

  1. Searched forcaptured_output("std,sys.std* =, andredirect_std* so there may be some missing instances. I manually reviewed the ones listed to check if replacement seemed doable (for instancetest_calendar.py needsTextIOWrapper(BytesIO) notStringIO, so cannot be easily swapped).

Metadata

Metadata

Assignees

No one assigned

    Labels

    testsTests in the Lib/test dirtype-refactorCode refactoring (with no changes in behavior)

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions


      [8]ページ先頭

      ©2009-2025 Movatter.jp