Title: GH-94438: Fix `RuntimeWarning` for jump tests in `test_sys_settrace` by gaogaotiantian · Pull Request #111341 · python/cpython · GitHub
Open Graph Title: GH-94438: Fix `RuntimeWarning` for jump tests in `test_sys_settrace` by gaogaotiantian · Pull Request #111341 · python/cpython
X Title: GH-94438: Fix `RuntimeWarning` for jump tests in `test_sys_settrace` by gaogaotiantian · Pull Request #111341 · python/cpython
Description: A couple of new tests were introduced to test_sys_settrace in #111237, however, two of them triggered a RuntimeWarning: ./python -m test test_sys_settrace -m test_jump_is_not_none_forwards Using random seed: 53646886 0:00:00 load avg: 0.44 Run 1 test sequentially 0:00:00 load avg: 0.44 [1/1] test_sys_settrace /home/gaogaotiantian/programs/mycpython/Lib/test/test_sys_settrace.py:1947: RuntimeWarning: assigning None to 1 unbound local frame.f_lineno = self.firstLine + self.jumpTo == Tests result: SUCCESS == This is because the jump happens before all the local variables are assigned: @jump_test(1, 4, [5]) def test_jump_is_not_none_forwards(output): x = None if x is not None: output.append(3) else: output.append(5) The test jumps on line 1 - before x is assigned to None. So when frame.f_lineno is being set, a warning is generated to alert the users that the unbound local variables are being set to None. This does not affect the validity or the result of the test, but I don't think it's intended, and it is not the best practice. Especially considering that the decorator can already take care of such warnings. In this PR, two different fixes were applied to the problematic tests to maximize the diversity: Add the warning to expected result Start from line 2 so x is assigned. A warning checker is also introduced so this won't happen in the future - if a test is not expecting a warning, then a warning is treated as an error. This might not be the best practice for all tests globally, but in this specific case, we do have "expected warnings" and it should count. Issue: gh-94438
Open Graph Description: A couple of new tests were introduced to test_sys_settrace in #111237, however, two of them triggered a RuntimeWarning: ./python -m test test_sys_settrace -m test_jump_is_not_none_forwards Using ra...
X Description: A couple of new tests were introduced to test_sys_settrace in #111237, however, two of them triggered a RuntimeWarning: ./python -m test test_sys_settrace -m test_jump_is_not_none_forwards Using ra...
Opengraph URL: https://github.com/python/cpython/pull/111341
X: @github
Domain: github.com
| route-pattern | /:user_id/:repository/pull/:id/files(.:format) |
| route-controller | pull_requests |
| route-action | files |
| fetch-nonce | v2:0fa3ee74-a755-51be-b71a-6d82ba366450 |
| current-catalog-service-hash | ae870bc5e265a340912cde392f23dad3671a0a881730ffdadd82f2f57d81641b |
| request-id | D328:3D0535:A34B22:DB9FD8:69697F88 |
| html-safe-nonce | 8c0d7682ed3d353059e45658dfca962a96c37fcf88f233b459d5163791928d92 |
| visitor-payload | eyJyZWZlcnJlciI6IiIsInJlcXVlc3RfaWQiOiJEMzI4OjNEMDUzNTpBMzRCMjI6REI5RkQ4OjY5Njk3Rjg4IiwidmlzaXRvcl9pZCI6IjQ2OTgwMDQ0Mzg5NTk4ODIxMjAiLCJyZWdpb25fZWRnZSI6ImlhZCIsInJlZ2lvbl9yZW5kZXIiOiJpYWQifQ== |
| visitor-hmac | 22ad7eb977b72ffdace3efef22da9045b03ae83559b04b3f83fb9006456eda88 |
| hovercard-subject-tag | pull_request:1573937097 |
| github-keyboard-shortcuts | repository,pull-request-list,pull-request-conversation,pull-request-files-changed,copilot |
| google-site-verification | Apib7-x98H0j5cPqHWwSMm6dNU4GmODRoqxLiDzdx9I |
| octolytics-url | https://collector.github.com/github/collect |
| analytics-location | / |
| fb:app_id | 1401488693436528 |
| apple-itunes-app | app-id=1477376905, app-argument=https://github.com/python/cpython/pull/111341/files |
| twitter:image | https://avatars.githubusercontent.com/u/13121107?s=400&v=4 |
| twitter:card | summary_large_image |
| og:image | https://avatars.githubusercontent.com/u/13121107?s=400&v=4 |
| og:image:alt | A couple of new tests were introduced to test_sys_settrace in #111237, however, two of them triggered a RuntimeWarning: ./python -m test test_sys_settrace -m test_jump_is_not_none_forwards Using ra... |
| og:site_name | GitHub |
| og:type | object |
| hostname | github.com |
| expected-hostname | github.com |
| None | f33e4b94c8824ab2b434d82a94139432fb5ebee9df4b75304140ad22508c4a77 |
| turbo-cache-control | no-preview |
| diff-view | unified |
| go-import | github.com/python/cpython git https://github.com/python/cpython.git |
| octolytics-dimension-user_id | 1525981 |
| octolytics-dimension-user_login | python |
| octolytics-dimension-repository_id | 81598961 |
| octolytics-dimension-repository_nwo | python/cpython |
| octolytics-dimension-repository_public | true |
| octolytics-dimension-repository_is_fork | false |
| octolytics-dimension-repository_network_root_id | 81598961 |
| octolytics-dimension-repository_network_root_nwo | python/cpython |
| turbo-body-classes | logged-out env-production page-responsive |
| disable-turbo | true |
| browser-stats-url | https://api.github.com/_private/browser/stats |
| browser-errors-url | https://api.github.com/_private/browser/errors |
| release | 48f380098b30acbb700b04f1724481ca10d574fc |
| ui-target | full |
| theme-color | #1e2327 |
| color-scheme | light dark |
Links:
Viewport: width=device-width