diff options
author | Armin Rigo <arigo@tunes.org> | 2021-06-20 20:31:53 +0200 |
---|---|---|
committer | Armin Rigo <arigo@tunes.org> | 2021-06-20 20:31:53 +0200 |
commit | 1d2de7dc29904d571069b947d3ec0d5b5dbed19c (patch) | |
tree | e8c1635762dd410216a4bb487ac4c3dd2586db94 /testing | |
parent | 1531a5c0c27cbc8c17bb721b936899c9ce24f329 (diff) | |
download | cffi-1d2de7dc29904d571069b947d3ec0d5b5dbed19c.tar.gz |
fix tests for py.test running on CPython v3.10.0b3
Diffstat (limited to 'testing')
-rw-r--r-- | testing/cffi0/test_function.py | 10 | ||||
-rw-r--r-- | testing/support.py | 5 |
2 files changed, 8 insertions, 7 deletions
diff --git a/testing/cffi0/test_function.py b/testing/cffi0/test_function.py index 4f2c864..b4bb23d 100644 --- a/testing/cffi0/test_function.py +++ b/testing/cffi0/test_function.py @@ -5,7 +5,7 @@ import math, os, sys import ctypes.util from cffi.backend_ctypes import CTypesBackend from testing.udir import udir -from testing.support import FdWriteCapture +from testing.support import FdWriteCapture, StdErrCapture from .backend_tests import needs_dlopen_none try: @@ -227,13 +227,9 @@ class TestFunction(object): def cb(): return returnvalue fptr = ffi.callback("void(*)(void)", cb) - old_stderr = sys.stderr - try: - sys.stderr = StringIO() + with StdErrCapture() as f: returned = fptr() - printed = sys.stderr.getvalue() - finally: - sys.stderr = old_stderr + printed = f.getvalue() assert returned is None if returnvalue is None: assert printed == '' diff --git a/testing/support.py b/testing/support.py index de8131c..6339a94 100644 --- a/testing/support.py +++ b/testing/support.py @@ -33,9 +33,14 @@ class StdErrCapture(object): from io import StringIO self.old_stderr = sys.stderr sys.stderr = f = StringIO() + if hasattr(sys, '__unraisablehook__'): # work around pytest + self.old_unraisablebook = sys.unraisablehook # on recent CPythons + sys.unraisablehook = sys.__unraisablehook__ return f def __exit__(self, *args): sys.stderr = self.old_stderr + if hasattr(self, 'old_unraisablebook'): + sys.unraisablehook = self.old_unraisablebook class FdWriteCapture(object): |