Tests that duplicate `py::module_local` class bindings work across modules
()
| 56 | |
| 57 | |
| 58 | def test_local_bindings(): |
| 59 | """Tests that duplicate `py::module_local` class bindings work across modules""" |
| 60 | |
| 61 | # Make sure we can load the second module with the conflicting (but local) definition: |
| 62 | import pybind11_cross_module_tests as cm |
| 63 | |
| 64 | i1 = m.LocalType(5) |
| 65 | assert i1.get() == 4 |
| 66 | assert i1.get3() == 8 |
| 67 | |
| 68 | i2 = cm.LocalType(10) |
| 69 | assert i2.get() == 11 |
| 70 | assert i2.get2() == 12 |
| 71 | |
| 72 | assert not hasattr(i1, "get2") |
| 73 | assert not hasattr(i2, "get3") |
| 74 | |
| 75 | # Loading within the local module |
| 76 | assert m.local_value(i1) == 5 |
| 77 | assert cm.local_value(i2) == 10 |
| 78 | |
| 79 | # Cross-module loading works as well (on failure, the type loader looks for |
| 80 | # external module-local converters): |
| 81 | assert m.local_value(i2) == 10 |
| 82 | assert cm.local_value(i1) == 5 |
| 83 | |
| 84 | |
| 85 | def test_nonlocal_failure(): |