|
1 | 1 | from __future__ import absolute_import
|
2 | 2 |
|
3 | 3 | from contextlib import contextmanager
|
| 4 | +from textwrap import dedent |
4 | 5 | import os
|
5 | 6 | import sys
|
6 | 7 | import re
|
@@ -263,6 +264,17 @@ def assert_installed(self, pkg_name, editable=True, with_files=[],
|
263 | 264 | )
|
264 | 265 |
|
265 | 266 |
|
| 267 | +def make_check_stderr_message(stderr, line, reason): |
| 268 | + """ |
| 269 | + Create an exception message to use inside check_stderr(). |
| 270 | + """ |
| 271 | + return dedent("""\ |
| 272 | + {reason}: |
| 273 | + Caused by line: {line!r} |
| 274 | + Complete stderr: {stderr} |
| 275 | + """).format(stderr=stderr, line=line, reason=reason) |
| 276 | + |
| 277 | + |
266 | 278 | def check_stderr(
|
267 | 279 | stderr, allow_stderr_warning=None, allow_stderr_error=None,
|
268 | 280 | ):
|
@@ -293,22 +305,34 @@ def check_stderr(
|
293 | 305 |
|
294 | 306 | lines = stderr.splitlines()
|
295 | 307 | for line in lines:
|
| 308 | + # First check for logging errors which are sent directly to stderr |
| 309 | + # and so bypass any configured log formatter. The |
| 310 | + # "--- Logging error ---" string is used in Python 3.4+, and |
| 311 | + # "Logged from file " is used in Python 2. |
| 312 | + if (line.startswith('--- Logging error ---') or |
| 313 | + line.startswith('Logged from file ')): |
| 314 | + reason = 'stderr has a logging error, which is never allowed' |
| 315 | + msg = make_check_stderr_message(stderr, line=line, reason=reason) |
| 316 | + raise RuntimeError(msg) |
| 317 | + |
296 | 318 | if line.startswith('ERROR: '):
|
297 |
| - raise RuntimeError( |
| 319 | + reason = ( |
298 | 320 | 'stderr has an unexpected error '
|
299 |
| - '(pass allow_stderr_error=True to permit this): {}' |
300 |
| - .format(line) |
| 321 | + '(pass allow_stderr_error=True to permit this)' |
301 | 322 | )
|
| 323 | + msg = make_check_stderr_message(stderr, line=line, reason=reason) |
| 324 | + raise RuntimeError(msg) |
302 | 325 | if allow_stderr_warning:
|
303 | 326 | continue
|
304 | 327 |
|
305 | 328 | if (line.startswith('WARNING: ') or
|
306 | 329 | line.startswith(DEPRECATION_MSG_PREFIX)):
|
307 |
| - raise RuntimeError( |
| 330 | + reason = ( |
308 | 331 | 'stderr has an unexpected warning '
|
309 |
| - '(pass allow_stderr_warning=True to permit this): {}' |
310 |
| - .format(line) |
| 332 | + '(pass allow_stderr_warning=True to permit this)' |
311 | 333 | )
|
| 334 | + msg = make_check_stderr_message(stderr, line=line, reason=reason) |
| 335 | + raise RuntimeError(msg) |
312 | 336 |
|
313 | 337 |
|
314 | 338 | class PipTestEnvironment(TestFileEnvironment):
|
|
0 commit comments