Skip to content

Commit c22a5b8

Browse files
authored
Update test_interpreter.cpp
1 parent edefef4 commit c22a5b8

1 file changed

Lines changed: 4 additions & 5 deletions

File tree

tests/test_embed/test_interpreter.cpp

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -137,11 +137,7 @@ TEST_CASE("Override cache") {
137137
}
138138

139139
TEST_CASE("Import error handling") {
140-
auto module_ = py::module_::import("widget_module");
141-
142-
// Also verify submodules work
143-
REQUIRE(module_.attr("add")(1, 41).cast<int>() == 42);
144-
REQUIRE(module_.attr("sub").attr("add")(1, 41).cast<int>() == 42);
140+
REQUIRE_NOTHROW(py::module_::import("widget_module"));
145141

146142
REQUIRE_THROWS_WITH(py::module_::import("throw_exception"), "ImportError: C++ Error");
147143
REQUIRE_THROWS_WITH(py::module_::import("throw_error_already_set"),
@@ -323,6 +319,9 @@ TEST_CASE("Restart the interpreter") {
323319
// C++ modules can be reloaded.
324320
auto cpp_module = py::module_::import("widget_module");
325321
REQUIRE(cpp_module.attr("add")(1, 2).cast<int>() == 3);
322+
323+
// Also verify submodules work
324+
REQUIRE(module_.attr("sub").attr("add")(1, 41).cast<int>() == 42);
326325

327326
// C++ type information is reloaded and can be used in python modules.
328327
auto py_module = py::module_::import("test_interpreter");

0 commit comments

Comments
 (0)