|
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 |
@@ -378,8 +379,12 @@ def _waitfor(func, pathname, waitall=False): |
378 | 379 | # Increase the timeout and try again |
379 | 380 | time.sleep(timeout) |
380 | 381 | timeout *= 2 |
381 | | - warnings.warn('tests may fail, delete still pending for ' + pathname, |
382 | | - RuntimeWarning, stacklevel=4) |
| 382 | + logging.getLogger(__name__).warning( |
| 383 | + 'tests may fail, delete still pending for %s', |
| 384 | + pathname, |
| 385 | + stack_info=True, |
| 386 | + stacklevel=4, |
| 387 | + ) |
383 | 388 |
|
384 | 389 | def _unlink(filename): |
385 | 390 | _waitfor(os.unlink, filename) |
@@ -494,9 +499,14 @@ def temp_dir(path=None, quiet=False): |
494 | 499 | except OSError as exc: |
495 | 500 | if not quiet: |
496 | 501 | raise |
497 | | - warnings.warn(f'tests may fail, unable to create ' |
498 | | - f'temporary directory {path!r}: {exc}', |
499 | | - RuntimeWarning, stacklevel=3) |
| 502 | + logging.getLogger(__name__).warning( |
| 503 | + "tests may fail, unable to create temporary directory %r: %s", |
| 504 | + path, |
| 505 | + exc, |
| 506 | + exc_info=exc, |
| 507 | + stack_info=True, |
| 508 | + stacklevel=3, |
| 509 | + ) |
500 | 510 | if dir_created: |
501 | 511 | pid = os.getpid() |
502 | 512 | try: |
@@ -527,9 +537,15 @@ def change_cwd(path, quiet=False): |
527 | 537 | except OSError as exc: |
528 | 538 | if not quiet: |
529 | 539 | raise |
530 | | - warnings.warn(f'tests may fail, unable to change the current working ' |
531 | | - f'directory to {path!r}: {exc}', |
532 | | - RuntimeWarning, stacklevel=3) |
| 540 | + logging.getLogger(__name__).warning( |
| 541 | + 'tests may fail, unable to change the current working directory ' |
| 542 | + 'to %r: %s', |
| 543 | + path, |
| 544 | + exc, |
| 545 | + exc_info=exc, |
| 546 | + stack_info=True, |
| 547 | + stacklevel=3, |
| 548 | + ) |
533 | 549 | try: |
534 | 550 | yield os.getcwd() |
535 | 551 | finally: |
|
0 commit comments