@@ -157,7 +157,7 @@ set(PYBIND11_TEST_FILES
157157 test_methods_and_attributes
158158 test_modules
159159 test_multiple_inheritance
160- test_multiple_interpreters/test_multiple_interpreters .py
160+ test_multiple_interpreters.py
161161 test_native_enum
162162 test_numpy_array
163163 test_numpy_dtypes
@@ -578,8 +578,34 @@ add_custom_target(
578578 USES_TERMINAL )
579579
580580if (NOT PYBIND11_CUDA_TESTS)
581- # Multiple interpreters tests are in a separate subdirectory
582- add_subdirectory (test_multiple_interpreters )
581+ set (PYBIND11_MULTIPLE_INTERPRETERS_TEST_FILES test_multiple_interpreters.py)
582+
583+ set (PYBIND11_MULTIPLE_INTERPRETERS_TEST_MODULES
584+ mod_per_interpreter_gil mod_shared_interpreter_gil mod_per_interpreter_gil_with_singleton)
585+
586+ # These modules don't get mixed with other test modules because those aren't subinterpreter safe.
587+ foreach (mod IN LISTS PYBIND11_MULTIPLE_INTERPRETERS_TEST_MODULES)
588+ pybind11_add_module ("${mod} " THIN_LTO "${mod} .cpp" )
589+ pybind11_enable_warnings ("${mod} " )
590+ endforeach ()
591+
592+ # Put the built modules next to `pybind11_tests.so` so that the test scripts can find them.
593+ get_target_property (pybind11_tests_output_directory pybind11_tests LIBRARY_OUTPUT_DIRECTORY )
594+ foreach (mod IN LISTS PYBIND11_MULTIPLE_INTERPRETERS_TEST_MODULES)
595+ set_target_properties ("${mod} " PROPERTIES LIBRARY_OUTPUT_DIRECTORY
596+ "${pybind11_tests_output_directory} " )
597+ endforeach ()
598+
599+ if (PYBIND11_TEST_SMART_HOLDER)
600+ foreach (mod IN LISTS PYBIND11_MULTIPLE_INTERPRETERS_TEST_MODULES)
601+ target_compile_definitions (
602+ "${mod} "
603+ PUBLIC
604+ -DPYBIND11_RUN_TESTING_WITH_SMART_HOLDER_AS_DEFAULT_BUT_NEVER_USE_IN_PRODUCTION_PLEASE )
605+ endforeach ()
606+ endif ()
607+
608+ add_dependencies (pytest ${PYBIND11_MULTIPLE_INTERPRETERS_TEST_MODULES} )
583609endif ()
584610
585611if (PYBIND11_TEST_OVERRIDE)
0 commit comments