Skip to content

Finalizers in the scope stack will not be executed if one finalizer raises an exception #3569

@sangongs

Description

@sangongs

When one finalizer raises an exception, the finalizers remain in the scope stack will be skipped.

Test case:

    def test_teardown_multiple_scopes_one_fails(self, testdir):
        module_teardown = []
        def fin_func():
            raise Exception("oops1")
        def fin_module():
            module_teardown.append("fin_module")
        item = testdir.getitem("def test_func(): pass")
        ss = runner.SetupState()
        ss.addfinalizer(fin_module, item.listchain()[-2])
        ss.addfinalizer(fin_func, item)
        ss.prepare(item)
        with pytest.raises(Exception) as err:
            ss.teardown_exact(item, None)
        assert module_teardown

Metadata

Metadata

Assignees

No one assigned

    Labels

    topic: fixturesanything involving fixtures directly or indirectlytype: bugproblem that needs to be addressed

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions