|
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 |
@@ -405,8 +406,12 @@ def _waitfor(func, pathname, waitall=False): |
405 | 406 | # Increase the timeout and try again |
406 | 407 | time.sleep(timeout) |
407 | 408 | timeout *= 2 |
408 | | - warnings.warn('tests may fail, delete still pending for ' + pathname, |
409 | | - RuntimeWarning, stacklevel=4) |
| 409 | + logging.getLogger(__name__).warning( |
| 410 | + 'tests may fail, delete still pending for %s', |
| 411 | + pathname, |
| 412 | + stack_info=True, |
| 413 | + stacklevel=4, |
| 414 | + ) |
410 | 415 |
|
411 | 416 | def _unlink(filename): |
412 | 417 | _waitfor(os.unlink, filename) |
@@ -521,9 +526,14 @@ def temp_dir(path=None, quiet=False): |
521 | 526 | except OSError as exc: |
522 | 527 | if not quiet: |
523 | 528 | raise |
524 | | - warnings.warn(f'tests may fail, unable to create ' |
525 | | - f'temporary directory {path!r}: {exc}', |
526 | | - RuntimeWarning, stacklevel=3) |
| 529 | + logging.getLogger(__name__).warning( |
| 530 | + "tests may fail, unable to create temporary directory %r: %s", |
| 531 | + path, |
| 532 | + exc, |
| 533 | + exc_info=exc, |
| 534 | + stack_info=True, |
| 535 | + stacklevel=3, |
| 536 | + ) |
527 | 537 | if dir_created: |
528 | 538 | pid = os.getpid() |
529 | 539 | try: |
@@ -554,9 +564,15 @@ def change_cwd(path, quiet=False): |
554 | 564 | except OSError as exc: |
555 | 565 | if not quiet: |
556 | 566 | raise |
557 | | - warnings.warn(f'tests may fail, unable to change the current working ' |
558 | | - f'directory to {path!r}: {exc}', |
559 | | - RuntimeWarning, stacklevel=3) |
| 567 | + logging.getLogger(__name__).warning( |
| 568 | + 'tests may fail, unable to change the current working directory ' |
| 569 | + 'to %r: %s', |
| 570 | + path, |
| 571 | + exc, |
| 572 | + exc_info=exc, |
| 573 | + stack_info=True, |
| 574 | + stacklevel=3, |
| 575 | + ) |
560 | 576 | try: |
561 | 577 | yield os.getcwd() |
562 | 578 | finally: |
|
0 commit comments