File tree Expand file tree Collapse file tree 1 file changed +12
-6
lines changed Expand file tree Collapse file tree 1 file changed +12
-6
lines changed Original file line number Diff line number Diff line change @@ -111,19 +111,25 @@ PYBIND11_EMBEDDED_MODULE(embedded_smart_holder, m) {
111111}
112112
113113TEST_CASE (" Embedded smart holder test" ) {
114+ py::exec (R"(
115+ import embedded_smart_holder
114116
115- auto module = py::module_::import (" embedded_smart_holder" );
117+ class ItemDerived(embedded_smart_holder.Item):
118+ def getInt(self):
119+ return 42
120+ )" );
116121
117- auto o = module . attr ( " Item " ) (); // create py
122+ auto py_item_derived = py::globals ()[ " ItemDerived " ] ();
118123
119- auto i = o .cast <std::shared_ptr<Item>>(); // cast cpp
124+ auto item = py_item_derived .cast <std::shared_ptr<Item>>()-> getInt (); // cast cpp
120125
121- if (i ->getInt () != 42 ) // test cpp
126+ if (item ->getInt () != 42 ) // test cpp
122127 throw std::runtime_error (" Not 42" );
123128
124- o = py::object (); // release py
129+ py_item_derived = py::object (); // release py
130+ py::module::import (" gc" ).attr (" collect" )();
125131
126- if (i ->getInt () != 42 ) // test cpp
132+ if (item ->getInt () != 42 ) // test cpp
127133 throw std::runtime_error (" Not 42 after release" );
128134}
129135
You can’t perform that action at this time.
0 commit comments