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 — bpo-36829: Document test.support.catch_unraisable_exception() by vstinner · Pull Request #13554 · python/cpython

bpo-36829: Document test.support.catch_unraisable_exception() #13554

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.

Sign up for GitHub

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
vstinner merged 1 commit into python:master from vstinner:catch_unraisable2
May 24, 2019

Uh oh!

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

Merged

bpo-36829: Document test.support.catch_unraisable_exception() #13554

Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
1 commit
Select commit
dc0dc43
bpo-36829: Document test.support.catch_unraisable_exception()
vstinner May 24, 2019
File filter
Filter by extension

Clear filters
Conversations
Failed to load comments.
Loading

Uh oh!

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

Jump to
Jump to file
Failed to load files.
Loading

Uh oh!

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

Diff view
Diff view

There are no files selected for viewing

20 changes: 20 additions & 0 deletions 20 Doc/library/test.rst
Show comments
View file
Open in desktop
Original file line number Diff line number Diff line change
Expand Up @@ -1081,6 +1081,26 @@ The :mod:`test.support` module defines the following functions:
:exc:`PermissionError` is raised.


.. function:: catch_unraisable_exception()

Context manager catching unraisable exception using
:func:`sys.unraisablehook`.

Usage::

with support.catch_unraisable_exception() as cm:
# code creating an "unraisable exception"
...

# check the unraisable exception: use cm.unraisable
...

# cm.unraisable attribute no longer exists at this point
# (to break a reference cycle)

.. versionadded:: 3.8


.. function:: find_unused_port(family=socket.AF_INET, socktype=socket.SOCK_STREAM)

Returns an unused port that should be suitable for binding. This is
Expand Down
8 changes: 5 additions & 3 deletions 8 Lib/test/support/__init__.py
Show comments
View file
Open in desktop
Original file line number Diff line number Diff line change
Expand Up @@ -3043,12 +3043,14 @@ class catch_unraisable_exception:
Usage:

with support.catch_unraisable_exception() as cm:
# code creating an "unraisable exception"
...

# check the expected unraisable exception: use cm.unraisable
# check the unraisable exception: use cm.unraisable
...

# cm.unraisable is None here (to break a reference cycle)
# cm.unraisable attribute no longer exists at this point
# (to break a reference cycle)
"""

def __init__(self):
Expand All @@ -3065,5 +3067,5 @@ def __enter__(self):

def __exit__(self, *exc_info):
# Clear the unraisable exception to explicitly break a reference cycle
self.unraisable = None
del self.unraisable
sys.unraisablehook = self._old_hook
20 changes: 6 additions & 14 deletions 20 Lib/test/test_io.py
Show comments
View file
Open in desktop
Original file line number Diff line number Diff line change
Expand Up @@ -1098,18 +1098,14 @@ def test_error_through_destructor(self):
# Test that the exception state is not modified by a destructor,
# even if close() fails.
rawio = self.CloseFailureIO()
try:
with support.catch_unraisable_exception() as cm:
with self.assertRaises(AttributeError):
self.tp(rawio).xyzzy
with support.catch_unraisable_exception() as cm:
with self.assertRaises(AttributeError):
self.tp(rawio).xyzzy

if not IOBASE_EMITS_UNRAISABLE:
self.assertIsNone(cm.unraisable)
elif cm.unraisable is not None:
self.assertEqual(cm.unraisable.exc_type, OSError)
finally:
# Explicitly break reference cycle
cm = None

def test_repr(self):
raw = self.MockRawIO()
Expand Down Expand Up @@ -2854,18 +2850,14 @@ def test_error_through_destructor(self):
# Test that the exception state is not modified by a destructor,
# even if close() fails.
rawio = self.CloseFailureIO()
try:
with support.catch_unraisable_exception() as cm:
with self.assertRaises(AttributeError):
self.TextIOWrapper(rawio).xyzzy
with support.catch_unraisable_exception() as cm:
with self.assertRaises(AttributeError):
self.TextIOWrapper(rawio).xyzzy

if not IOBASE_EMITS_UNRAISABLE:
self.assertIsNone(cm.unraisable)
elif cm.unraisable is not None:
self.assertEqual(cm.unraisable.exc_type, OSError)
finally:
# Explicitly break reference cycle
cm = None

# Systematic tests of the text I/O API

Expand Down
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 01402503 — 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.