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

Function test_no_placement_new

tests/test_factory_constructors.py:311–334  ·  view source on GitHub ↗

Prior to 2.2, `py::init<...>` relied on the type supporting placement new; this tests a class without placement new support.

(capture)

Source from the content-addressed store, hash-verified

309
310@pytest.mark.skipif("env.GRAALPY", reason="Cannot reliably trigger GC")
311def test_no_placement_new(capture):
312 """Prior to 2.2, `py::init<...>` relied on the type supporting placement
313 new; this tests a class without placement new support."""
314 with capture:
315 a = m.NoPlacementNew(123)
316
317 found = re.search(r"^operator new called, returning (\d+)\n$", str(capture))
318 assert found
319 assert a.i == 123
320 with capture:
321 del a
322 pytest.gc_collect()
323 assert capture == "operator delete called on " + found.group(1)
324
325 with capture:
326 b = m.NoPlacementNew()
327
328 found = re.search(r"^operator new called, returning (\d+)\n$", str(capture))
329 assert found
330 assert b.i == 100
331 with capture:
332 del b
333 pytest.gc_collect()
334 assert capture == "operator delete called on " + found.group(1)
335
336
337def test_multiple_inheritance():

Callers

nothing calls this directly

Calls 2

strClass · 0.85
NoPlacementNewMethod · 0.80

Tested by

no test coverage detected