An exception raised during emit() should fail the test. The default behavior of logging is to print "Logging error" to stderr with the call stack and some extra details. pytest overrides this behavior to propagate the exception.
(pytester: Pytester)
| 1116 | |
| 1117 | |
| 1118 | def test_logging_emit_error(pytester: Pytester) -> None: |
| 1119 | """An exception raised during emit() should fail the test. |
| 1120 | |
| 1121 | The default behavior of logging is to print "Logging error" |
| 1122 | to stderr with the call stack and some extra details. |
| 1123 | |
| 1124 | pytest overrides this behavior to propagate the exception. |
| 1125 | """ |
| 1126 | pytester.makepyfile( |
| 1127 | """ |
| 1128 | import logging |
| 1129 | |
| 1130 | def test_bad_log(): |
| 1131 | logging.warning('oops', 'first', 2) |
| 1132 | """ |
| 1133 | ) |
| 1134 | result = pytester.runpytest() |
| 1135 | result.assert_outcomes(failed=1) |
| 1136 | result.stdout.fnmatch_lines( |
| 1137 | [ |
| 1138 | "====* FAILURES *====", |
| 1139 | "*not all arguments converted during string formatting*", |
| 1140 | ] |
| 1141 | ) |
| 1142 | |
| 1143 | |
| 1144 | def test_logging_emit_error_supressed(pytester: Pytester) -> None: |
nothing calls this directly
no test coverage detected