'Ensure exceptions raised during teardown by a finalizer are suppressed
until all finalizers are called, re-raising the first exception (#2440)'

def test_request_subrequest_addfinalizer_exceptions(self, testdir):

    testdir.makepyfile("\n                                                import    pytest\n                                                l    =    []\n                                                def    _excepts(where):\n                                                                raise    Exception('Error    in    %s    fixture'    %    where)\n                                                @pytest.fixture\n                                                def    subrequest(request):\n                                                                return    request\n                                                @pytest.fixture\n                                                def    something(subrequest):\n                                                                subrequest.addfinalizer(lambda:    l.append(1))\n                                                                subrequest.addfinalizer(lambda:    l.append(2))\n                                                                subrequest.addfinalizer(lambda:    _excepts('something'))\n                                                @pytest.fixture\n                                                def    excepts(subrequest):\n                                                                subrequest.addfinalizer(lambda:    _excepts('excepts'))\n                                                                subrequest.addfinalizer(lambda:    l.append(3))\n                                                def    test_first(something,    excepts):\n                                                                pass\n                                                def    test_second():\n                                                                assert    l    ==    [3,    2,    1]\n                                ")
    result = testdir.runpytest()
    result.stdout.fnmatch_lines(['*Exception:    Error    in    excepts    fixture', '*    2    passed,    1    error    in    *'])
