|
1 | 1 | """ command line options, ini-file and conftest.py processing. """
|
2 | 2 | import argparse
|
| 3 | +import contextlib |
3 | 4 | import copy
|
4 | 5 | import enum
|
5 | 6 | import inspect
|
@@ -511,34 +512,36 @@ def _importconftest(self, conftestpath):
|
511 | 512 | # Using Path().resolve() is better than py.path.realpath because
|
512 | 513 | # it resolves to the correct path/drive in case-insensitive file systems (#5792)
|
513 | 514 | key = Path(str(conftestpath)).resolve()
|
514 |
| - try: |
| 515 | + |
| 516 | + with contextlib.suppress(KeyError): |
515 | 517 | return self._conftestpath2mod[key]
|
516 |
| - except KeyError: |
517 |
| - pkgpath = conftestpath.pypkgpath() |
518 |
| - if pkgpath is None: |
519 |
| - _ensure_removed_sysmodule(conftestpath.purebasename) |
520 |
| - try: |
521 |
| - mod = conftestpath.pyimport() |
522 |
| - if ( |
523 |
| - hasattr(mod, "pytest_plugins") |
524 |
| - and self._configured |
525 |
| - and not self._using_pyargs |
526 |
| - ): |
527 |
| - _fail_on_non_top_pytest_plugins(conftestpath, self._confcutdir) |
528 |
| - except Exception: |
529 |
| - raise ConftestImportFailure(conftestpath, sys.exc_info()) |
530 |
| - |
531 |
| - self._conftest_plugins.add(mod) |
532 |
| - self._conftestpath2mod[key] = mod |
533 |
| - dirpath = conftestpath.dirpath() |
534 |
| - if dirpath in self._dirpath2confmods: |
535 |
| - for path, mods in self._dirpath2confmods.items(): |
536 |
| - if path and path.relto(dirpath) or path == dirpath: |
537 |
| - assert mod not in mods |
538 |
| - mods.append(mod) |
539 |
| - self.trace("loading conftestmodule {!r}".format(mod)) |
540 |
| - self.consider_conftest(mod) |
541 |
| - return mod |
| 518 | + |
| 519 | + pkgpath = conftestpath.pypkgpath() |
| 520 | + if pkgpath is None: |
| 521 | + _ensure_removed_sysmodule(conftestpath.purebasename) |
| 522 | + |
| 523 | + try: |
| 524 | + mod = conftestpath.pyimport() |
| 525 | + if ( |
| 526 | + hasattr(mod, "pytest_plugins") |
| 527 | + and self._configured |
| 528 | + and not self._using_pyargs |
| 529 | + ): |
| 530 | + _fail_on_non_top_pytest_plugins(conftestpath, self._confcutdir) |
| 531 | + except Exception as e: |
| 532 | + raise ConftestImportFailure(conftestpath, sys.exc_info()) from e |
| 533 | + |
| 534 | + self._conftest_plugins.add(mod) |
| 535 | + self._conftestpath2mod[key] = mod |
| 536 | + dirpath = conftestpath.dirpath() |
| 537 | + if dirpath in self._dirpath2confmods: |
| 538 | + for path, mods in self._dirpath2confmods.items(): |
| 539 | + if path and path.relto(dirpath) or path == dirpath: |
| 540 | + assert mod not in mods |
| 541 | + mods.append(mod) |
| 542 | + self.trace("loading conftestmodule {!r}".format(mod)) |
| 543 | + self.consider_conftest(mod) |
| 544 | + return mod |
542 | 545 |
|
543 | 546 | #
|
544 | 547 | # API for bootstrapping plugin loading
|
|
0 commit comments