Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allow to use assert outside pytest.raises block #2543

Open
dandreevv opened this issue Nov 16, 2022 · 1 comment
Open

Allow to use assert outside pytest.raises block #2543

dandreevv opened this issue Nov 16, 2022 · 1 comment
Labels
rule request Adding a new rule

Comments

@dandreevv
Copy link

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.

@dandreevv dandreevv added the rule request Adding a new rule label Nov 16, 2022
@dandreevv dandreevv changed the title Allow use assert outside pytest.raises block Allow to use assert outside pytest.raises block Nov 16, 2022
@blablatdinov
Copy link
Contributor

@sobolevn what is your opinion on this issue?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
rule request Adding a new rule
Projects
None yet
Development

No branches or pull requests

2 participants