Skip to content

For "only_rerun" allow access exception attributes #230

Description

@simon-liebehenschel

I often have cases like below when I do not fail a test based on a specific exception attributes.

In case of pytest-rerunfailures the logic can look like:

@pytest.mark.flaky(
    only_rerun=ClientResponseError,
    condition=lambda error: error.status in {429, 500},
)
async def test_request():
    await request("www.example.com")



@pytest.mark.flaky(
    only_rerun=CustomDatabaseError,
    condition=lambda error: error["code"] != 123456,
)
async def test_database():
    await database.set("foo", "bar")



def _callback(error: Exception) -> bool:
    if isinstance(error, CustomDatabaseError): ...
    if isinstance(error, AnotherError): ...
    raise 

@pytest.mark.flaky(
    only_rerun=[CustomDatabaseError, AnotherError],
    condition=_callback,
)
async def test_database():
    await database.set("foo", "bar")

There are also some 3rd-party packages that raise custom exceptions and I must handle an exception in different ways based on some attributes.

Question:
Is this functionality out of scope of the current plugin and I should write a separate plugin?

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions