Skip to content

Allow to use assert outside pytest.raises block #2543

@dandreevv

Description

@dandreevv

Rule request

There is impossible to validate correctness of custom exception.

Thesis

I propose to allow assert statement to use variable outside context manager.

with pytest.raises(CustomError) as exc_info:
    client.send_sms(sms)

    assert exc_info.value.http_status == expected_status
    assert exc_info.value.description == expected_description

Code above raise an error:

148:16   WPS441 Found control variable used after block: exc_info
  assert exc_info.value.http_status == expected_status

Reasoning

It is typical use case for pytest.

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