From 157626ac251acba14c10fdbce6582404fc6c4f3d Mon Sep 17 00:00:00 2001 From: "Ralf W. Grosse-Kunstleve" Date: Fri, 8 Jul 2022 13:34:22 -0700 Subject: [PATCH 1/4] Similar to PR #4053 at commit f572bdfc0af94af8f6f5f0d2659915c357a37349, but against master (instead of smart_holder). --- tests/CMakeLists.txt | 2 ++ tests/namespace_visibility_1.cpp | 3 +++ tests/namespace_visibility_2.cpp | 3 +++ tests/test_namespace_visibility.py | 13 +++++++++++++ 4 files changed, 21 insertions(+) create mode 100644 tests/namespace_visibility_1.cpp create mode 100644 tests/namespace_visibility_2.cpp create mode 100644 tests/test_namespace_visibility.py diff --git a/tests/CMakeLists.txt b/tests/CMakeLists.txt index 7296cd1b81..4118ccdab0 100644 --- a/tests/CMakeLists.txt +++ b/tests/CMakeLists.txt @@ -140,6 +140,7 @@ set(PYBIND11_TEST_FILES test_methods_and_attributes test_modules test_multiple_inheritance + test_namespace_visibility.py test_numpy_array test_numpy_dtypes test_numpy_vectorize @@ -217,6 +218,7 @@ tests_extra_targets("test_exceptions.py;test_local_bindings.py;test_stl.py;test_ # And add additional targets for other tests. tests_extra_targets("test_exceptions.py" "cross_module_interleaved_error_already_set") tests_extra_targets("test_gil_scoped.py" "cross_module_gil_utils") +tests_extra_targets("test_namespace_visibility.py" "namespace_visibility_1;namespace_visibility_2") set(PYBIND11_EIGEN_REPO "https://gitlab.com/libeigen/eigen.git" diff --git a/tests/namespace_visibility_1.cpp b/tests/namespace_visibility_1.cpp new file mode 100644 index 0000000000..96e602e38e --- /dev/null +++ b/tests/namespace_visibility_1.cpp @@ -0,0 +1,3 @@ +#include "pybind11/pybind11.h" + +PYBIND11_MODULE(namespace_visibility_1, m) { m.doc() = "ns_vis_1"; } diff --git a/tests/namespace_visibility_2.cpp b/tests/namespace_visibility_2.cpp new file mode 100644 index 0000000000..b596cd3693 --- /dev/null +++ b/tests/namespace_visibility_2.cpp @@ -0,0 +1,3 @@ +#include "pybind11/pybind11.h" + +PYBIND11_MODULE(namespace_visibility_2, m) { m.doc() = "ns_vis_2"; } diff --git a/tests/test_namespace_visibility.py b/tests/test_namespace_visibility.py new file mode 100644 index 0000000000..e641449177 --- /dev/null +++ b/tests/test_namespace_visibility.py @@ -0,0 +1,13 @@ +import namespace_visibility_1 +import namespace_visibility_2 +import pytest + + +def test_namespace_visibility(): + modules = ( + namespace_visibility_1, + namespace_visibility_2, + ) + for m in modules: + if m.__doc__ != "ns_vis_1": + pytest.skip(f"Not surprised: {m.__doc__}") From 8b28edd67dbd7835735d7cfe123280f8edb53dd6 Mon Sep 17 00:00:00 2001 From: "Ralf W. Grosse-Kunstleve" Date: Fri, 8 Jul 2022 14:20:35 -0700 Subject: [PATCH 2/4] Try `import pybind11_cross_module_tests` from test_namespace_visibility.py --- tests/test_namespace_visibility.py | 2 ++ 1 file changed, 2 insertions(+) diff --git a/tests/test_namespace_visibility.py b/tests/test_namespace_visibility.py index e641449177..4a534f2f6b 100644 --- a/tests/test_namespace_visibility.py +++ b/tests/test_namespace_visibility.py @@ -1,9 +1,11 @@ import namespace_visibility_1 import namespace_visibility_2 +import pybind11_cross_module_tests as cm import pytest def test_namespace_visibility(): + del cm # Unused. modules = ( namespace_visibility_1, namespace_visibility_2, From 6b6b3eb8c3f8ca6fdaad27cd34160f68c78e2dea Mon Sep 17 00:00:00 2001 From: "Ralf W. Grosse-Kunstleve" Date: Fri, 8 Jul 2022 14:28:12 -0700 Subject: [PATCH 3/4] Fix quick-shot trial. --- tests/test_namespace_visibility.py | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/tests/test_namespace_visibility.py b/tests/test_namespace_visibility.py index 4a534f2f6b..27a0f063c9 100644 --- a/tests/test_namespace_visibility.py +++ b/tests/test_namespace_visibility.py @@ -1,11 +1,12 @@ import namespace_visibility_1 import namespace_visibility_2 -import pybind11_cross_module_tests as cm import pytest +import pybind11_cross_module_tests as cm + def test_namespace_visibility(): - del cm # Unused. + assert cm.__doc__ is not None modules = ( namespace_visibility_1, namespace_visibility_2, From 5d22f1753abb757ab2f16e4c93eddcd655e88897 Mon Sep 17 00:00:00 2001 From: "Ralf W. Grosse-Kunstleve" Date: Fri, 8 Jul 2022 15:55:19 -0700 Subject: [PATCH 4/4] Rename test_namespace_visibility.py to test_exc_namespace_visibility.py, so that it is imported by pytest before test_exceptions.py --- tests/CMakeLists.txt | 5 +++-- ...espace_visibility.py => test_exc_namespace_visibility.py} | 0 2 files changed, 3 insertions(+), 2 deletions(-) rename tests/{test_namespace_visibility.py => test_exc_namespace_visibility.py} (100%) diff --git a/tests/CMakeLists.txt b/tests/CMakeLists.txt index 4118ccdab0..d07be61ca9 100644 --- a/tests/CMakeLists.txt +++ b/tests/CMakeLists.txt @@ -131,6 +131,7 @@ set(PYBIND11_TEST_FILES test_eigen test_enum test_eval + test_exc_namespace_visibility.py test_exceptions test_factory_constructors test_gil_scoped @@ -140,7 +141,6 @@ set(PYBIND11_TEST_FILES test_methods_and_attributes test_modules test_multiple_inheritance - test_namespace_visibility.py test_numpy_array test_numpy_dtypes test_numpy_vectorize @@ -218,7 +218,8 @@ tests_extra_targets("test_exceptions.py;test_local_bindings.py;test_stl.py;test_ # And add additional targets for other tests. tests_extra_targets("test_exceptions.py" "cross_module_interleaved_error_already_set") tests_extra_targets("test_gil_scoped.py" "cross_module_gil_utils") -tests_extra_targets("test_namespace_visibility.py" "namespace_visibility_1;namespace_visibility_2") +tests_extra_targets("test_exc_namespace_visibility.py" + "namespace_visibility_1;namespace_visibility_2") set(PYBIND11_EIGEN_REPO "https://gitlab.com/libeigen/eigen.git" diff --git a/tests/test_namespace_visibility.py b/tests/test_exc_namespace_visibility.py similarity index 100% rename from tests/test_namespace_visibility.py rename to tests/test_exc_namespace_visibility.py