|
1 | 1 | import collections.abc |
2 | 2 | import contextlib |
3 | 3 | import errno |
| 4 | +import logging |
4 | 5 | import os |
5 | 6 | import re |
6 | 7 | import stat |
@@ -361,8 +362,12 @@ def _waitfor(func, pathname, waitall=False): |
361 | 362 | # Increase the timeout and try again |
362 | 363 | time.sleep(timeout) |
363 | 364 | timeout *= 2 |
364 | | - warnings.warn('tests may fail, delete still pending for ' + pathname, |
365 | | - RuntimeWarning, stacklevel=4) |
| 365 | + logging.getLogger(__name__).warning( |
| 366 | + 'tests may fail, delete still pending for %s', |
| 367 | + pathname, |
| 368 | + stack_info=True, |
| 369 | + stacklevel=4, |
| 370 | + ) |
366 | 371 |
|
367 | 372 | def _unlink(filename): |
368 | 373 | _waitfor(os.unlink, filename) |
@@ -477,9 +482,14 @@ def temp_dir(path=None, quiet=False): |
477 | 482 | except OSError as exc: |
478 | 483 | if not quiet: |
479 | 484 | raise |
480 | | - warnings.warn(f'tests may fail, unable to create ' |
481 | | - f'temporary directory {path!r}: {exc}', |
482 | | - RuntimeWarning, stacklevel=3) |
| 485 | + logging.getLogger(__name__).warning( |
| 486 | + "tests may fail, unable to create temporary directory %r: %s", |
| 487 | + path, |
| 488 | + exc, |
| 489 | + exc_info=exc, |
| 490 | + stack_info=True, |
| 491 | + stacklevel=3, |
| 492 | + ) |
483 | 493 | if dir_created: |
484 | 494 | pid = os.getpid() |
485 | 495 | try: |
@@ -510,9 +520,15 @@ def change_cwd(path, quiet=False): |
510 | 520 | except OSError as exc: |
511 | 521 | if not quiet: |
512 | 522 | raise |
513 | | - warnings.warn(f'tests may fail, unable to change the current working ' |
514 | | - f'directory to {path!r}: {exc}', |
515 | | - RuntimeWarning, stacklevel=3) |
| 523 | + logging.getLogger(__name__).warning( |
| 524 | + 'tests may fail, unable to change the current working directory ' |
| 525 | + 'to %r: %s', |
| 526 | + path, |
| 527 | + exc, |
| 528 | + exc_info=exc, |
| 529 | + stack_info=True, |
| 530 | + stacklevel=3, |
| 531 | + ) |
516 | 532 | try: |
517 | 533 | yield os.getcwd() |
518 | 534 | finally: |
|
0 commit comments