Skip to content

gh-157649: Merge test_cppext into test_cext - #158176

Merged
vstinner merged 6 commits into
python:mainfrom
vstinner:merge_test_cext
Sep 25, 2026
Merged

vstinner merged 6 commits into
python:mainfrom
vstinner:merge_test_cext

Conversation

@vstinner

@vstinner vstinner commented Sep 25, 2026 •

Copy link
Copy Markdown
Member
  • test_cext now uses a single virtual environment for all tests. It makes the test way faster since creating a virtual environment is quite slow.
  • Add Py_TARGET_ABI3T test on C++.
  • Move macro tests from module exec function to test_macros().
  • Call Py_BEGIN_CRITICAL_SECTION() on a fresh dictionary object, rather than on the module.
  • Rename some environment variables to always use "CPYTHON_TEST_" prefix.
  • Replace support.MS_WINDOWS with MSVC to be more explicit.
  • Move macro tests to test_macros().
* test_cext now uses a single virtual environment for all tests.
  It makes the test way faster since creating a virtual environment
  is quite slow.
* Add Py_TARGET_ABI3T test on C++.
* Move macro tests from module exec function to test_macros().
* Call Py_BEGIN_CRITICAL_SECTION() on a fresh dictionary object,
  rather than on the module.
* Rename some environment variables to always use "CPYTHON_TEST_"
  prefix.
* Replace support.MS_WINDOWS with MSVC to be more explicit.
* Move macro tests to test_macros().
@bedevere-bot

Copy link
Copy Markdown

🤖 New build scheduled with the buildbot fleet by @vstinner for commit 18d8ef5 🤖

Results will be shown at:

https://buildbot.python.org/all/#/grid?branch=refs%2Fpull%2F158176%2Fmerge

If you want to schedule another build, you need to add the 🔨 test-with-buildbots label again.

@bedevere-bot bedevere-bot removed the 🔨 test-with-buildbots Test PR w/ buildbots; report in status section label Sep 25, 2026
@vstinner vstinner added the 🔨 test-with-buildbots Test PR w/ buildbots; report in status section label Sep 25, 2026
@bedevere-bot

Copy link
Copy Markdown

🤖 New build scheduled with the buildbot fleet by @vstinner for commit 8ee942f 🤖

Results will be shown at:

https://buildbot.python.org/all/#/grid?branch=refs%2Fpull%2F158176%2Fmerge

If you want to schedule another build, you need to add the 🔨 test-with-buildbots label again.

@bedevere-bot bedevere-bot removed the 🔨 test-with-buildbots Test PR w/ buildbots; report in status section label Sep 25, 2026
@vstinner

Copy link
Copy Markdown
Member Author

test_cext and test_cppext had a lot of duplicated code with only minor differences. Merging the two tests makes sure that most code is shared between C and C++ tests to keep code consistent.

For example, this PR adds PyUnicode tests in C and adds Py_TARGET_ABI3T tests in C++.

@vstinner

Copy link
Copy Markdown
Member Author

test_cext fails on macOS:

ERROR: test_build (test.test_cext.TestPublicCpp.test_build)
ERROR: test_build_intel_asm (test.test_cext.TestPublicCpp.test_build_intel_asm)

Example:

Building wheels for collected packages: internal__test_cppext
  Building wheel for internal__test_cppext (pyproject.toml): started
  Running command Building wheel for internal__test_cppext (pyproject.toml)
  Language: C++
  Source: extension.cpp
  CC env var: 'gcc'
  CXX env var: <missing>
  CFLAGS env var: <missing>
  CPPFLAGS env var: <missing>
  CXXFLAGS env var: <missing>
  extra_compile_args: ['-Werror', '-DMODULE_NAME=_test_cppext', '-pedantic-errors', '-Wno-long-long']
  running bdist_wheel
  running build
  running build_ext
  building '_test_cppext' extension
  creating build/temp.macosx-13.7-x86_64-cpython-316t-pydebug
  /usr/bin/clang++ -fno-omit-frame-pointer -mno-omit-leaf-frame-pointer -fno-strict-overflow -Wsign-compare -g -Og -Wall -I/Users/buildbot/buildarea/pull_request.itamaro-macos-intel-aws.nogil/build/build/test_python_98426æ/tempcwd/env/include -I/Users/buildbot/buildarea/pull_request.itamaro-macos-intel-aws.nogil/build/Include -I/Users/buildbot/buildarea/pull_request.itamaro-macos-intel-aws.nogil/build -c extension.cpp -o build/temp.macosx-13.7-x86_64-cpython-316t-pydebug/extension.o -Werror -DMODULE_NAME=_test_cppext -pedantic-errors -Wno-long-long
  In file included from extension.cpp:3:
  In file included from ./extension.c:16:
  In file included from /Users/buildbot/buildarea/pull_request.itamaro-macos-intel-aws.nogil/build/Include/Python.h:72:
  In file included from /Users/buildbot/buildarea/pull_request.itamaro-macos-intel-aws.nogil/build/Include/pymem.h:103:
  /Users/buildbot/buildarea/pull_request.itamaro-macos-intel-aws.nogil/build/Include/cpython/pymem.h:28:39: error: commas at the end of enumerator lists are a C++11 extension [-Werror,-Wc++11-extensions]
      PYMEM_ALLOCATOR_MIMALLOC_DEBUG = 8,
                                        ^
  In file included from extension.cpp:3:
  In file included from ./extension.c:16:
  In file included from /Users/buildbot/buildarea/pull_request.itamaro-macos-intel-aws.nogil/build/Include/Python.h:79:
  In file included from /Users/buildbot/buildarea/pull_request.itamaro-macos-intel-aws.nogil/build/Include/object.h:742:
  /Users/buildbot/buildarea/pull_request.itamaro-macos-intel-aws.nogil/build/Include/cpython/object.h:476:36: error: commas at the end of enumerator lists are a C++11 extension [-Werror,-Wc++11-extensions]
      PyRefTracer_TRACKER_REMOVED = 2,
                                     ^
  In file included from extension.cpp:3:
  In file included from ./extension.c:16:
  In file included from /Users/buildbot/buildarea/pull_request.itamaro-macos-intel-aws.nogil/build/Include/Python.h:99:
  In file included from /Users/buildbot/buildarea/pull_request.itamaro-macos-intel-aws.nogil/build/Include/dictobject.h:113:
  /Users/buildbot/buildarea/pull_request.itamaro-macos-intel-aws.nogil/build/Include/cpython/dictobject.h:90:27: error: commas at the end of enumerator lists are a C++11 extension [-Werror,-Wc++11-extensions]
      PY_FOREACH_DICT_EVENT(PY_DEF_EVENT)
                            ^
  In file included from extension.cpp:3:
  In file included from ./extension.c:16:
  In file included from /Users/buildbot/buildarea/pull_request.itamaro-macos-intel-aws.nogil/build/Include/Python.h:106:
  /Users/buildbot/buildarea/pull_request.itamaro-macos-intel-aws.nogil/build/Include/cpython/funcobject.h:142:27: error: commas at the end of enumerator lists are a C++11 extension [-Werror,-Wc++11-extensions]
      PY_FOREACH_FUNC_EVENT(PY_DEF_EVENT)
                            ^
  In file included from extension.cpp:3:
  In file included from ./extension.c:16:
  In file included from /Users/buildbot/buildarea/pull_request.itamaro-macos-intel-aws.nogil/build/Include/Python.h:110:
  /Users/buildbot/buildarea/pull_request.itamaro-macos-intel-aws.nogil/build/Include/cpython/code.h:236:27: error: commas at the end of enumerator lists are a C++11 extension [-Werror,-Wc++11-extensions]
      PY_FOREACH_CODE_EVENT(PY_DEF_EVENT)
                            ^
  In file included from extension.cpp:3:
  In file included from ./extension.c:16:
  In file included from /Users/buildbot/buildarea/pull_request.itamaro-macos-intel-aws.nogil/build/Include/Python.h:129:
  /Users/buildbot/buildarea/pull_request.itamaro-macos-intel-aws.nogil/build/Include/cpython/context.h:36:28: error: commas at the end of enumerator lists are a C++11 extension [-Werror,-Wc++11-extensions]
      Py_CONTEXT_SWITCHED = 1,
                             ^
  6 errors generated.
  error: command '/usr/bin/clang++' failed with exit code 1

It seems like clang++ uses a C++ version older than C++11 by default. It's likely the old Apple clang++ which uses gnu++98 by default. I changed the two affected TestPublicCpp tests to use C++11 by default on macOS.

It's unclear to me why the same passed on macOS before this change. But I don't have access to macOS, so I cannot investigate. Well, my change should fix macOS support.

@vstinner

Copy link
Copy Markdown
Member Author

!buildbot x86-64 MacOS

@bedevere-bot

Copy link
Copy Markdown

🤖 New build scheduled with the buildbot fleet by @vstinner for commit ee31df3 🤖

Results will be shown at:

https://buildbot.python.org/all/#/grid?branch=refs%2Fpull%2F158176%2Fmerge

The command will test the builders whose names match following regular expression: x86-64 MacOS

The builders matched are:

  • x86-64 macOS PR
  • x86-64 MacOS Intel NoGIL PR
  • x86-64 MacOS Intel ASAN NoGIL PR
@vstinner

Copy link
Copy Markdown
Member Author

!buildbot AMD64 Fedora Stable

@bedevere-bot

Copy link
Copy Markdown

🤖 New build scheduled with the buildbot fleet by @vstinner for commit ee31df3 🤖

Results will be shown at:

https://buildbot.python.org/all/#/grid?branch=refs%2Fpull%2F158176%2Fmerge

The command will test the builders whose names match following regular expression: AMD64 Fedora Stable

The builders matched are:

  • AMD64 Fedora Stable LTO + PGO PR
  • AMD64 Fedora Stable LTO PR
  • AMD64 Fedora Stable PR
  • AMD64 Fedora Stable Clang PR
  • AMD64 Fedora Stable Clang Installed PR
  • AMD64 Fedora Stable Refleaks PR
@vstinner
vstinner enabled auto-merge (squash) September 25, 2026 22:00
@vstinner
vstinner merged commit b71989d into python:main Sep 25, 2026
52 checks passed
@vstinner
vstinner deleted the merge_test_cext branch September 25, 2026 22:31
@bedevere-app

bedevere-app Bot commented Oct 12, 2026

Copy link
Copy Markdown

GH-159264 is a backport of this pull request to the 3.15 branch.

vstinner added a commit that referenced this pull request Oct 12, 2026
* test_cext now uses a single virtual environment for all tests.
  It makes the test way faster since creating a virtual environment
  is quite slow.
* Add Py_TARGET_ABI3T test on C++.
* Move macro tests from module exec function to test_macros().
* Call Py_BEGIN_CRITICAL_SECTION() on a fresh dictionary object,
  rather than on the module.
* Rename some environment variables to always use "CPYTHON_TEST_"
  prefix.
* Replace support.MS_WINDOWS with MSVC to be more explicit.
* Move macro tests to test_macros().
* On macOS, use C++11 by default.

(cherry picked from commit b71989d)
vstinner added a commit that referenced this pull request Oct 13, 2026
#159276)

* [3.15] gh-157649: Merge test_cppext into test_cext (#158176) (#159264)

* test_cext now uses a single virtual environment for all tests.
  It makes the test way faster since creating a virtual environment
  is quite slow.
* Add Py_TARGET_ABI3T test on C++.
* Move macro tests from module exec function to test_macros().
* Call Py_BEGIN_CRITICAL_SECTION() on a fresh dictionary object,
  rather than on the module.
* Rename some environment variables to always use "CPYTHON_TEST_"
  prefix.
* Replace support.MS_WINDOWS with MSVC to be more explicit.
* Move macro tests to test_macros().
* On macOS, use C++11 by default.

(cherry picked from commit b71989d)
(cherry picked from commit 364db5d)

* Fix warning about unused dict
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

2 participants