File tree Expand file tree Collapse file tree 1 file changed +21
-1
lines changed Expand file tree Collapse file tree 1 file changed +21
-1
lines changed Original file line number Diff line number Diff line change @@ -184,7 +184,7 @@ TEST_CASE("Custom PyConfig") {
184184 py::initialize_interpreter ();
185185}
186186
187- TEST_CASE (" Custom PyConfig with argv" ) {
187+ TEST_CASE (" scoped_interpreter with PyConfig_InitIsolatedConfig and argv" ) {
188188 py::finalize_interpreter ();
189189 {
190190 PyConfig config;
@@ -199,6 +199,26 @@ TEST_CASE("Custom PyConfig with argv") {
199199 }
200200 py::initialize_interpreter ();
201201}
202+
203+ TEST_CASE (" scoped_interpreter with PyConfig_InitPythonConfig and argv" ) {
204+ py::finalize_interpreter ();
205+ {
206+ PyConfig config;
207+ PyConfig_InitPythonConfig (&config);
208+
209+ // `initialize_interpreter() overrides the default value for config.parse_argv (`1`) by
210+ // changing it to `0`. This test exercises `scoped_interpreter` with the default config.
211+ char *argv[] = {strdup (" a.out" ), strdup (" arg1" )};
212+ py::scoped_interpreter argv_scope (&config, 2 , argv);
213+ std::free (argv[0 ]);
214+ std::free (argv[1 ]);
215+ auto module = py::module::import (" test_interpreter" );
216+ auto py_widget = module .attr (" DerivedWidget" )(" The question" );
217+ const auto &cpp_widget = py_widget.cast <const Widget &>();
218+ REQUIRE (cpp_widget.argv0 () == " arg1" );
219+ }
220+ py::initialize_interpreter ();
221+ }
202222#endif
203223
204224TEST_CASE (" Add program dir to path pre-PyConfig" ) {
You can’t perform that action at this time.
0 commit comments