(self, importasmod, tw_mock)
| 1125 | assert tw_mock.lines[20] == ":9: ValueError" |
| 1126 | |
| 1127 | def test_exc_chain_repr(self, importasmod, tw_mock): |
| 1128 | mod = importasmod( |
| 1129 | """ |
| 1130 | class Err(Exception): |
| 1131 | pass |
| 1132 | def f(): |
| 1133 | try: |
| 1134 | g() |
| 1135 | except Exception as e: |
| 1136 | raise Err() from e |
| 1137 | finally: |
| 1138 | h() |
| 1139 | def g(): |
| 1140 | raise ValueError() |
| 1141 | |
| 1142 | def h(): |
| 1143 | raise AttributeError() |
| 1144 | """ |
| 1145 | ) |
| 1146 | excinfo = pytest.raises(AttributeError, mod.f) |
| 1147 | r = excinfo.getrepr(style="long") |
| 1148 | r.toterminal(tw_mock) |
| 1149 | for line in tw_mock.lines: |
| 1150 | print(line) |
| 1151 | assert tw_mock.lines[0] == "" |
| 1152 | assert tw_mock.lines[1] == " def f():" |
| 1153 | assert tw_mock.lines[2] == " try:" |
| 1154 | assert tw_mock.lines[3] == "> g()" |
| 1155 | assert tw_mock.lines[4] == "" |
| 1156 | line = tw_mock.get_write_msg(5) |
| 1157 | assert line.endswith("mod.py") |
| 1158 | assert tw_mock.lines[6] == ":6: " |
| 1159 | assert tw_mock.lines[7] == ("_ ", None) |
| 1160 | assert tw_mock.lines[8] == "" |
| 1161 | assert tw_mock.lines[9] == " def g():" |
| 1162 | assert tw_mock.lines[10] == "> raise ValueError()" |
| 1163 | assert tw_mock.lines[11] == "E ValueError" |
| 1164 | assert tw_mock.lines[12] == "" |
| 1165 | line = tw_mock.get_write_msg(13) |
| 1166 | assert line.endswith("mod.py") |
| 1167 | assert tw_mock.lines[14] == ":12: ValueError" |
| 1168 | assert tw_mock.lines[15] == "" |
| 1169 | assert ( |
| 1170 | tw_mock.lines[16] |
| 1171 | == "The above exception was the direct cause of the following exception:" |
| 1172 | ) |
| 1173 | assert tw_mock.lines[17] == "" |
| 1174 | assert tw_mock.lines[18] == " def f():" |
| 1175 | assert tw_mock.lines[19] == " try:" |
| 1176 | assert tw_mock.lines[20] == " g()" |
| 1177 | assert tw_mock.lines[21] == " except Exception as e:" |
| 1178 | assert tw_mock.lines[22] == "> raise Err() from e" |
| 1179 | assert tw_mock.lines[23] == "E test_exc_chain_repr0.mod.Err" |
| 1180 | assert tw_mock.lines[24] == "" |
| 1181 | line = tw_mock.get_write_msg(25) |
| 1182 | assert line.endswith("mod.py") |
| 1183 | assert tw_mock.lines[26] == ":8: Err" |
| 1184 | assert tw_mock.lines[27] == "" |
nothing calls this directly
no test coverage detected