File tree Expand file tree Collapse file tree 1 file changed +18
-0
lines changed Expand file tree Collapse file tree 1 file changed +18
-0
lines changed Original file line number Diff line number Diff line change @@ -184,6 +184,8 @@ TEST_CASE("Custom PyConfig") {
184184 py::initialize_interpreter ();
185185}
186186
187+ # include < iostream>
188+
187189TEST_CASE (" Custom PyConfig with argv" ) {
188190 py::finalize_interpreter ();
189191 {
@@ -197,6 +199,22 @@ TEST_CASE("Custom PyConfig with argv") {
197199 const auto &cpp_widget = py_widget.cast <const Widget &>();
198200 REQUIRE (cpp_widget.argv0 () == " a.out" );
199201 }
202+
203+ {
204+ PyConfig config;
205+ PyConfig_InitPythonConfig (&config);
206+
207+ // Parse arguments the way python normally does, and strip the first argument (which is
208+ // expected to be "python")
209+ char *argv[] = {strdup (" python" ), strdup (" a.out" )};
210+ py::scoped_interpreter argv_scope (&config, 2 , argv);
211+ std::free (argv[0 ]);
212+ std::free (argv[1 ]);
213+ auto module = py::module::import (" test_interpreter" );
214+ auto py_widget = module .attr (" DerivedWidget" )(" The question" );
215+ const auto &cpp_widget = py_widget.cast <const Widget &>();
216+ REQUIRE (cpp_widget.argv0 () == " a.out" );
217+ }
200218 py::initialize_interpreter ();
201219}
202220#endif
You can’t perform that action at this time.
0 commit comments