File tree 1 file changed +18
-0
lines changed
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") {
184
184
py::initialize_interpreter ();
185
185
}
186
186
187
+ # include < iostream>
188
+
187
189
TEST_CASE (" Custom PyConfig with argv" ) {
188
190
py::finalize_interpreter ();
189
191
{
@@ -197,6 +199,22 @@ TEST_CASE("Custom PyConfig with argv") {
197
199
const auto &cpp_widget = py_widget.cast <const Widget &>();
198
200
REQUIRE (cpp_widget.argv0 () == " a.out" );
199
201
}
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
+ }
200
218
py::initialize_interpreter ();
201
219
}
202
220
#endif
You can’t perform that action at this time.
0 commit comments