Commit 051b79e
Make
* Add assert_on_exception parameter to RequestsMock
When set to True, assertions about unfired requests will be raised even
when an exception occurs in the context manager. This provides valuable
debugging context about which mocked requests were or weren't called
when debugging test failures.
By default (assert_on_exception=False), the assertion is suppressed to
avoid masking the original exception.
🤖 Generated with [Claude Code](https://claude.com/claude-code)
Co-Authored-By: Claude <[email protected]>
* Add decorator support for assert_on_exception
The @responses.activate decorator now accepts an assert_on_exception
parameter, providing a convenient way to enable assertion checking
even when exceptions occur:
@responses.activate(
assert_all_requests_are_fired=True,
assert_on_exception=True
)
def test_my_api():
...
This is consistent with the existing decorator support for
assert_all_requests_are_fired and registry parameters.
🤖 Generated with [Claude Code](https://claude.com/claude-code)
Co-Authored-By: Claude <[email protected]>
* Update CHANGES for assert_on_exception feature
Document the new assert_on_exception parameter in version 0.26.0.
This is a minor version bump (not patch) because we're adding new
functionality to the public API, even though it's fully backward
compatible with existing code.
🤖 Generated with [Claude Code](https://claude.com/claude-code)
Co-Authored-By: Claude <[email protected]>
* Always raise assertions on exception when assert_all_requests_are_fired=True
This is a breaking change that modifies the behavior of assert_all_requests_are_fired
to always raise assertions about unfired requests even when an exception occurs in
the context manager or decorated function.
Previously, when an exception occurred, assertions about unfired requests were
suppressed to avoid masking the original exception. However, this behavior hid
valuable debugging context about which mocked requests were or weren't called.
The new behavior always raises assertions (when assert_all_requests_are_fired=True),
with the original exception chained as context. This provides developers with complete
information about both the original failure and the state of mocked requests.
Changes:
- Updated __exit__ to always pass allow_assert=True to stop()
- Removed conditional logic that suppressed assertions on exception
- Updated tests to verify assertions are raised during exceptions
- Updated documentation to reflect new behavior
🤖 Generated with [Claude Code](https://claude.com/claude-code)
Co-Authored-By: Claude <[email protected]>
---------
Co-authored-by: Claude <[email protected]>
Co-authored-by: Mark Story <[email protected]>assert_all_requests_are_fired always assert on exception (#782)1 parent 0905cb8 commit 051b79e
File tree
4 files changed
+100
-10
lines changed- responses
- tests
4 files changed
+100
-10
lines changed| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
1 | | - | |
2 | | - | |
| 1 | + | |
| 2 | + | |
3 | 3 | | |
| 4 | + | |
| 5 | + | |
| 6 | + | |
| 7 | + | |
| 8 | + | |
4 | 9 | | |
5 | 10 | | |
| 11 | + | |
6 | 12 | | |
7 | 13 | | |
8 | 14 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
917 | 917 | | |
918 | 918 | | |
919 | 919 | | |
| 920 | + | |
| 921 | + | |
| 922 | + | |
| 923 | + | |
| 924 | + | |
| 925 | + | |
| 926 | + | |
| 927 | + | |
| 928 | + | |
| 929 | + | |
| 930 | + | |
| 931 | + | |
| 932 | + | |
| 933 | + | |
| 934 | + | |
| 935 | + | |
| 936 | + | |
| 937 | + | |
| 938 | + | |
| 939 | + | |
| 940 | + | |
| 941 | + | |
| 942 | + | |
| 943 | + | |
| 944 | + | |
920 | 945 | | |
921 | 946 | | |
922 | 947 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
226 | 226 | | |
227 | 227 | | |
228 | 228 | | |
229 | | - | |
230 | | - | |
| 229 | + | |
| 230 | + | |
231 | 231 | | |
232 | 232 | | |
233 | 233 | | |
| |||
991 | 991 | | |
992 | 992 | | |
993 | 993 | | |
994 | | - | |
995 | 994 | | |
996 | | - | |
| 995 | + | |
997 | 996 | | |
998 | 997 | | |
999 | 998 | | |
| |||
1008 | 1007 | | |
1009 | 1008 | | |
1010 | 1009 | | |
1011 | | - | |
1012 | | - | |
| 1010 | + | |
1013 | 1011 | | |
1014 | 1012 | | |
1015 | 1013 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
1163 | 1163 | | |
1164 | 1164 | | |
1165 | 1165 | | |
1166 | | - | |
1167 | | - | |
| 1166 | + | |
| 1167 | + | |
1168 | 1168 | | |
1169 | 1169 | | |
1170 | 1170 | | |
| 1171 | + | |
| 1172 | + | |
1171 | 1173 | | |
1172 | 1174 | | |
1173 | 1175 | | |
| |||
1217 | 1219 | | |
1218 | 1220 | | |
1219 | 1221 | | |
| 1222 | + | |
| 1223 | + | |
| 1224 | + | |
| 1225 | + | |
| 1226 | + | |
| 1227 | + | |
| 1228 | + | |
| 1229 | + | |
| 1230 | + | |
| 1231 | + | |
| 1232 | + | |
| 1233 | + | |
| 1234 | + | |
| 1235 | + | |
| 1236 | + | |
| 1237 | + | |
| 1238 | + | |
| 1239 | + | |
| 1240 | + | |
| 1241 | + | |
| 1242 | + | |
| 1243 | + | |
| 1244 | + | |
| 1245 | + | |
| 1246 | + | |
| 1247 | + | |
| 1248 | + | |
| 1249 | + | |
| 1250 | + | |
| 1251 | + | |
| 1252 | + | |
| 1253 | + | |
| 1254 | + | |
| 1255 | + | |
| 1256 | + | |
| 1257 | + | |
| 1258 | + | |
| 1259 | + | |
| 1260 | + | |
| 1261 | + | |
| 1262 | + | |
| 1263 | + | |
| 1264 | + | |
| 1265 | + | |
| 1266 | + | |
| 1267 | + | |
| 1268 | + | |
| 1269 | + | |
| 1270 | + | |
| 1271 | + | |
| 1272 | + | |
| 1273 | + | |
| 1274 | + | |
| 1275 | + | |
| 1276 | + | |
| 1277 | + | |
| 1278 | + | |
| 1279 | + | |
| 1280 | + | |
1220 | 1281 | | |
1221 | 1282 | | |
1222 | 1283 | | |
| |||
0 commit comments