pybind/pybind11

[BUG]: Test test_init_factory_basic fails

Open

#4467 aperta il 23 gen 2023

Vedi su GitHub
 (0 commenti) (0 reazioni) (0 assegnatari)C++ (2005 fork)batch import
bughelp wantedregression

Metriche repository

Star
 (14.677 star)
Metriche merge PR
 (Merge medio 5g 2h) (10 PR mergiate in 30 g)

Descrizione

Required prerequisites

What version (or hash if on master) of pybind11 are you using?

2.10.3

Problem description

________________________________________________________________________________________ test_init_factory_basic ________________________________________________________________________________________

    def test_init_factory_basic():
        """Tests py::init_factory() wrapper around various ways of returning the object"""
    
        cstats = [
            ConstructorStats.get(c)
            for c in [m.TestFactory1, m.TestFactory2, m.TestFactory3]
        ]
        cstats[0].alive()  # force gc
        n_inst = ConstructorStats.detail_reg_inst()
    
        x1 = m.TestFactory1(tag.unique_ptr, 3)
        assert x1.value == "3"
        y1 = m.TestFactory1(tag.pointer)
        assert y1.value == "(empty)"
        z1 = m.TestFactory1("hi!")
        assert z1.value == "hi!"
    
        assert ConstructorStats.detail_reg_inst() == n_inst + 3
    
        x2 = m.TestFactory2(tag.move)
        assert x2.value == "(empty2)"
        y2 = m.TestFactory2(tag.pointer, 7)
        assert y2.value == "7"
        z2 = m.TestFactory2(tag.unique_ptr, "hi again")
        assert z2.value == "hi again"
    
        assert ConstructorStats.detail_reg_inst() == n_inst + 6
    
        x3 = m.TestFactory3(tag.shared_ptr)
        assert x3.value == "(empty3)"
        y3 = m.TestFactory3(tag.pointer, 42)
        assert y3.value == "42"
        z3 = m.TestFactory3("bye")
        assert z3.value == "bye"
    
        for null_ptr_kind in [tag.null_ptr, tag.null_unique_ptr, tag.null_shared_ptr]:
            with pytest.raises(TypeError) as excinfo:
                m.TestFactory3(null_ptr_kind)
            assert (
                str(excinfo.value) == "pybind11::init(): factory function returned nullptr"
            )
    
        assert [i.alive() for i in cstats] == [3, 3, 3]
        assert ConstructorStats.detail_reg_inst() == n_inst + 9
    
        del x1, y2, y3, z3
        assert [i.alive() for i in cstats] == [2, 2, 1]
        assert ConstructorStats.detail_reg_inst() == n_inst + 5
        del x2, x3, y1, z1, z2
        assert [i.alive() for i in cstats] == [0, 0, 0]
        assert ConstructorStats.detail_reg_inst() == n_inst
    
>       assert [i.values() for i in cstats] == [
            ["3", "hi!"],
            ["7", "hi again"],
            ["42", "bye"],
        ]
E       AssertionError: assert [['33', '3', ...['42', 'bye']] == [['3', 'hi!']...['42', 'bye']]
E         At index 0 diff: ['33', '3', 'hi!'] != ['3', 'hi!']
E         Use -v to get more diff

cstats     = [<pybind11_tests.ConstructorStats object at 0x991925130>, <pybind11_tests.ConstructorStats object at 0x9919252f0>, <pybind11_tests.ConstructorStats object at 0x991925230>]
excinfo    = <ExceptionInfo TypeError('pybind11::init(): factory function returned nullptr') tblen=1>
n_inst     = 57
null_ptr_kind = <pybind11_tests.factory_constructors.tag.null_shared_ptr_tag object at 0x861c10cb0>

../../pybind11-2.10.3/tests/test_factory_constructors.py:62: AssertionError
----------------------------------------------------------------------------------------- Captured stdout call ------------------------------------------------------------------------------------------
### TestFactory1 @ 0x900682480 created 3
### TestFactory1 @ 0x900682460 created via default constructor
### TestFactory1 @ 0x93b6a2d80 created hi!
### TestFactory2 @ 0x93b6a2be0 created via default constructor
### TestFactory2 @ 0x9006824e0 created 7
### TestFactory2 @ 0x8210396d0 created hi again
### TestFactory2 @ 0x900682580 created via move constructor
### TestFactory2 @ 0x8210396d0 destroyed
### TestFactory3 @ 0x900682540 created via default constructor
### TestFactory3 @ 0x900682640 created 42
### TestFactory3 @ 0x900682620 created bye
### TestFactory1 @ 0x900682480 destroyed
### TestFactory2 @ 0x9006824e0 destroyed
### TestFactory3 @ 0x900682640 destroyed
### TestFactory3 @ 0x900682620 destroyed
### TestFactory2 @ 0x93b6a2be0 destroyed
### TestFactory3 @ 0x900682540 destroyed
### TestFactory1 @ 0x900682460 destroyed
### TestFactory1 @ 0x93b6a2d80 destroyed
### TestFactory2 @ 0x900682580 destroyed

Python-3.9 OS: FreeBSD 13.1

Reproducible example code

Test

Is this a regression? Put the last known working version here if it is.

Yes, this is a regression in 2.10.3

Guida contributor