MCPcopy Create free account
hub / github.com/pybind/pybind11 / test_local_bindings

Function test_local_bindings

tests/test_local_bindings.py:58–82  ·  view source on GitHub ↗

Tests that duplicate `py::module_local` class bindings work across modules

()

Source from the content-addressed store, hash-verified

56
57
58def 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
85def test_nonlocal_failure():

Callers

nothing calls this directly

Calls 2

hasattrFunction · 0.85
getMethod · 0.45

Tested by

no test coverage detected