Skip to content

Commit a6a7055

Browse files
committed
Relocate multiple-interpreters tests
1 parent e8ba231 commit a6a7055

File tree

6 files changed

+43
-21
lines changed

6 files changed

+43
-21
lines changed

include/pybind11/gil_safe_call_once.h

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -257,8 +257,7 @@ class gil_safe_call_once_and_store {
257257
} else {
258258
// Use unique_ptr for exception safety: if capsule creation throws,
259259
// the map is automatically deleted.
260-
auto storage_map_ptr
261-
= std::unique_ptr<call_once_storage_map_type>(new call_once_storage_map_type());
260+
auto storage_map_ptr = std::make_unique<call_once_storage_map_type>();
262261
// Create capsule with destructor to clean up the storage map when the interpreter
263262
// shuts down
264263
state_dict[PYBIND11_CALL_ONCE_STORAGE_MAP_ID]

tests/CMakeLists.txt

Lines changed: 3 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -157,7 +157,7 @@ set(PYBIND11_TEST_FILES
157157
test_methods_and_attributes
158158
test_modules
159159
test_multiple_inheritance
160-
test_multiple_interpreters.py
160+
test_multiple_interpreters/test_multiple_interpreters.py
161161
test_native_enum
162162
test_numpy_array
163163
test_numpy_dtypes
@@ -578,24 +578,8 @@ add_custom_target(
578578
USES_TERMINAL)
579579

580580
if(NOT PYBIND11_CUDA_TESTS)
581-
# This module doesn't get mixed with other test modules because those aren't subinterpreter safe.
582-
pybind11_add_module(mod_per_interpreter_gil THIN_LTO mod_per_interpreter_gil.cpp)
583-
pybind11_add_module(mod_shared_interpreter_gil THIN_LTO mod_shared_interpreter_gil.cpp)
584-
set_target_properties(mod_per_interpreter_gil PROPERTIES LIBRARY_OUTPUT_DIRECTORY
585-
"$<1:${CMAKE_CURRENT_BINARY_DIR}>")
586-
set_target_properties(mod_shared_interpreter_gil PROPERTIES LIBRARY_OUTPUT_DIRECTORY
587-
"$<1:${CMAKE_CURRENT_BINARY_DIR}>")
588-
if(PYBIND11_TEST_SMART_HOLDER)
589-
target_compile_definitions(
590-
mod_per_interpreter_gil
591-
PUBLIC -DPYBIND11_RUN_TESTING_WITH_SMART_HOLDER_AS_DEFAULT_BUT_NEVER_USE_IN_PRODUCTION_PLEASE
592-
)
593-
target_compile_definitions(
594-
mod_shared_interpreter_gil
595-
PUBLIC -DPYBIND11_RUN_TESTING_WITH_SMART_HOLDER_AS_DEFAULT_BUT_NEVER_USE_IN_PRODUCTION_PLEASE
596-
)
597-
endif()
598-
add_dependencies(pytest mod_per_interpreter_gil mod_shared_interpreter_gil)
581+
# Multiple interpreters tests are in a separate subdirectory
582+
add_subdirectory(test_multiple_interpreters)
599583
endif()
600584

601585
if(PYBIND11_TEST_OVERRIDE)
Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
# CMakeLists.txt -- Build system for the pybind11 multiple interpreters test suite
2+
#
3+
# Copyright (c) 2015 Wenzel Jakob <[email protected]>
4+
#
5+
# All rights reserved. Use of this source code is governed by a
6+
# BSD-style license that can be found in the LICENSE file.
7+
8+
set(PYBIND11_MULTIPLE_INTERPRETERS_TEST_FILES test_multiple_interpreters.py)
9+
10+
# These modules don't get mixed with other test modules because those aren't subinterpreter safe.
11+
pybind11_add_module(mod_per_interpreter_gil THIN_LTO mod_per_interpreter_gil.cpp)
12+
pybind11_add_module(mod_shared_interpreter_gil THIN_LTO mod_shared_interpreter_gil.cpp)
13+
pybind11_enable_warnings(mod_per_interpreter_gil)
14+
pybind11_enable_warnings(mod_shared_interpreter_gil)
15+
16+
# Put the built modules to the parent directory in the cmake build tree. So they can be found by
17+
# the test scripts.
18+
set_target_properties(mod_per_interpreter_gil PROPERTIES LIBRARY_OUTPUT_DIRECTORY
19+
"$<1:${CMAKE_CURRENT_BINARY_DIR}>/..")
20+
set_target_properties(mod_shared_interpreter_gil PROPERTIES LIBRARY_OUTPUT_DIRECTORY
21+
"$<1:${CMAKE_CURRENT_BINARY_DIR}>/..")
22+
23+
if(PYBIND11_TEST_SMART_HOLDER)
24+
target_compile_definitions(
25+
mod_per_interpreter_gil
26+
PUBLIC -DPYBIND11_RUN_TESTING_WITH_SMART_HOLDER_AS_DEFAULT_BUT_NEVER_USE_IN_PRODUCTION_PLEASE)
27+
target_compile_definitions(
28+
mod_shared_interpreter_gil
29+
PUBLIC -DPYBIND11_RUN_TESTING_WITH_SMART_HOLDER_AS_DEFAULT_BUT_NEVER_USE_IN_PRODUCTION_PLEASE)
30+
endif()
31+
32+
add_dependencies(pytest mod_per_interpreter_gil mod_shared_interpreter_gil)
33+
34+
# Convert relative to full file names and add to pytest test files
35+
list(TRANSFORM PYBIND11_MULTIPLE_INTERPRETERS_TEST_FILES PREPEND "${CMAKE_CURRENT_SOURCE_DIR}/")
36+
list(APPEND PYBIND11_ABS_PYTEST_FILES ${PYBIND11_MULTIPLE_INTERPRETERS_TEST_FILES})
37+
set(PYBIND11_ABS_PYTEST_FILES
38+
${PYBIND11_ABS_PYTEST_FILES}
39+
PARENT_SCOPE)

tests/mod_per_interpreter_gil.cpp renamed to tests/test_multiple_interpreters/mod_per_interpreter_gil.cpp

File renamed without changes.

tests/mod_shared_interpreter_gil.cpp renamed to tests/test_multiple_interpreters/mod_shared_interpreter_gil.cpp

File renamed without changes.

tests/test_multiple_interpreters.py renamed to tests/test_multiple_interpreters/test_multiple_interpreters.py

File renamed without changes.

0 commit comments

Comments
 (0)