mirror of
https://github.com/pybind/pybind11.git
synced 2026-04-19 22:39:09 +00:00
embed.h Python 3.11 config.use_environment=1 + PYTHONPATH test (#4119)
* Add debug fprintf to test_interpreter.cpp * Update `sys.path` from `PYTHONPATH` in Python >= 3.11 branch of `initialize_interpreter()` * Use `config.isolated = 0; config.use_environment = 1;` As suggsted by @vstinner here: https://github.com/pybind/pybind11/pull/4119#issuecomment-1219442853 * Add `TEST_CASE("PYTHONPATH is used to update sys.path")` * Fix clang-tidy error. * Use `_putenv_s()` under Windows. * Fix clang-tidy error: argument name ... in comment does not match parameter name * Remove slash from PYTHONPATH addition, to work around Windows slash-vs-backslash issue. * Use `py::str(...)` instead of `.attr("__str__")` as suggested by @skylion007 Co-authored-by: Aaron Gokaslan <skylion.aaron@gmail.com> Co-authored-by: Aaron Gokaslan <skylion.aaron@gmail.com>
This commit is contained in:
committed by
GitHub
parent
81f35d29c6
commit
68e6fdaa90
@@ -75,6 +75,13 @@ PYBIND11_EMBEDDED_MODULE(throw_error_already_set, ) {
|
||||
d["missing"].cast<py::object>();
|
||||
}
|
||||
|
||||
TEST_CASE("PYTHONPATH is used to update sys.path") {
|
||||
// The setup for this TEST_CASE is in catch.cpp!
|
||||
auto sys_path = py::str(py::module_::import("sys").attr("path")).cast<std::string>();
|
||||
REQUIRE_THAT(sys_path,
|
||||
Catch::Matchers::Contains("pybind11_test_embed_PYTHONPATH_2099743835476552"));
|
||||
}
|
||||
|
||||
TEST_CASE("Pass classes and data between modules defined in C++ and Python") {
|
||||
auto module_ = py::module_::import("test_interpreter");
|
||||
REQUIRE(py::hasattr(module_, "DerivedWidget"));
|
||||
|
||||
Reference in New Issue
Block a user