Skip to content

false unreachable error after pytest.raises block #8985

@rkm

Description

@rkm

Hi. mypy returns an unreachable error for code after a pytets.raises block:

$ cat t.py
import pytest

def testeroni() -> None:
    with pytest.raises(Exception):
        raise Exception("oh noes")
    print("hello there")

$ mypy --version
mypy 0.780

$ mypy t.py
t.py: note: In function "testeroni":
t.py:7: error: Statement is unreachable
        print("hello there")
        ^
Found 1 error in 1 file (checked 1 source file)

I'm actually not sure if this is a bug in mypy, since it might not be aware that pytest swallows the exception there. Any advice appreciated!

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions