()
| 1223 | |
| 1224 | |
| 1225 | def test_assert_matches() -> None: |
| 1226 | e = ValueError() |
| 1227 | |
| 1228 | # it's easy to do this |
| 1229 | assert RaisesExc(ValueError).matches(e) |
| 1230 | |
| 1231 | # but you don't get a helpful error |
| 1232 | with pytest.raises(AssertionError, match=r"assert False\n \+ where False = .*"): |
| 1233 | assert RaisesExc(TypeError).matches(e) |
| 1234 | |
| 1235 | with pytest.raises( |
| 1236 | AssertionError, |
| 1237 | match=wrap_escape( |
| 1238 | "`ValueError()` is not an instance of `TypeError`\n" |
| 1239 | "assert False\n" |
| 1240 | " + where False = matches(ValueError())\n" |
| 1241 | " + where matches = RaisesExc(TypeError).matches" |
| 1242 | ), |
| 1243 | ): |
| 1244 | # you'd need to do this arcane incantation |
| 1245 | assert (m := RaisesExc(TypeError)).matches(e), m.fail_reason |
| 1246 | |
| 1247 | # but even if we add assert_matches, will people remember to use it? |
| 1248 | # other than writing a linter rule, I don't think we can catch `assert RaisesExc(...).matches` |
| 1249 | # ... no wait pytest catches other asserts ... so we probably can?? |
| 1250 | |
| 1251 | |
| 1252 | # https://github.com/pytest-dev/pytest/issues/12504 |
nothing calls this directly
no test coverage detected