summaryrefslogtreecommitdiffstats
path: root/Lib/test/test_cppext.py
diff options
context:
space:
mode:
authorVictor Stinner <vstinner@python.org>2022-05-02 15:07:00 (GMT)
committerGitHub <noreply@github.com>2022-05-02 15:07:00 (GMT)
commit031397063e9c22711abfbf90f2617c8785cfc42c (patch)
tree08f64eeab6cbe6cebb51f44ddeb0f329c16ca9d3 /Lib/test/test_cppext.py
parentb11243e85e020ed2f524bdd83c339faf11ef03d4 (diff)
downloadcpython-031397063e9c22711abfbf90f2617c8785cfc42c.zip
cpython-031397063e9c22711abfbf90f2617c8785cfc42c.tar.gz
cpython-031397063e9c22711abfbf90f2617c8785cfc42c.tar.bz2
gh-92135: Fix _Py_reinterpret_cast() for const (#92138)
Fix C++ compiler warnings on cast macros, like _PyObject_CAST(), when casting a constant expression to a non constant type: use const_cast<> in C++. * In C++, Py_SAFE_DOWNCAST() now uses static_cast<> rather than reinterpret_cast<>. * Add tests to the _testcppext C++ extension. * test_cppext no longer captures stdout in verbose mode.
Diffstat (limited to 'Lib/test/test_cppext.py')
-rw-r--r--Lib/test/test_cppext.py18
1 files changed, 13 insertions, 5 deletions
diff --git a/Lib/test/test_cppext.py b/Lib/test/test_cppext.py
index c1d02bc..99f6062 100644
--- a/Lib/test/test_cppext.py
+++ b/Lib/test/test_cppext.py
@@ -1,5 +1,6 @@
# gh-91321: Build a basic C++ test extension to check that the Python C API is
# compatible with C++ and does not emit C++ compiler warnings.
+import contextlib
import os
import sys
import unittest
@@ -39,17 +40,24 @@ class TestCPPExt(unittest.TestCase):
sources=[SOURCE],
language='c++',
extra_compile_args=CPPFLAGS)
+ capture_stdout = (not support.verbose)
try:
try:
- with (support.captured_stdout() as stdout,
- support.swap_attr(sys, 'argv', ['setup.py', 'build_ext'])):
+ if capture_stdout:
+ stdout = support.captured_stdout()
+ else:
+ print()
+ stdout = contextlib.nullcontext()
+ with (stdout,
+ support.swap_attr(sys, 'argv', ['setup.py', 'build_ext', '--verbose'])):
setup(name="_testcppext", ext_modules=[cpp_ext])
return
except:
- # Show output on error
- print()
- print(stdout.getvalue())
+ if capture_stdout:
+ # Show output on error
+ print()
+ print(stdout.getvalue())
raise
except SystemExit:
self.fail("Build failed")