Skip to content

Commit ac666e8

Browse files
update
1 parent 9d5a967 commit ac666e8

File tree

1 file changed

+12
-6
lines changed

1 file changed

+12
-6
lines changed

tests/test_with_catch/test_interpreter.cpp

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -111,19 +111,25 @@ PYBIND11_EMBEDDED_MODULE(embedded_smart_holder, m) {
111111
}
112112

113113
TEST_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

0 commit comments

Comments
 (0)