Remove one of the tracebacks from conftest import failures
This removes the KeyError from the traceback chain when an conftest fails to import: return self._conftestpath2mod[key] E KeyError: WindowsPath('D:/projects/pytest/.tmp/root/foo/conftest.py') During handling of the above exception, another exception occurred: ... raise RuntimeError("some error") E RuntimeError: some error During handling of the above exception, another exception occurred: ... E _pytest.config.ConftestImportFailure: (...) By slightly changing the code, we can remove the first chain, which is often very confusing to users and doesn't help with anything. Fix #7223
This commit is contained in:
parent
d4dfe863c9
commit
5eaebc1900
|
@ -1,5 +1,6 @@
|
||||||
""" command line options, ini-file and conftest.py processing. """
|
""" command line options, ini-file and conftest.py processing. """
|
||||||
import argparse
|
import argparse
|
||||||
|
import contextlib
|
||||||
import copy
|
import copy
|
||||||
import enum
|
import enum
|
||||||
import inspect
|
import inspect
|
||||||
|
@ -511,12 +512,14 @@ class PytestPluginManager(PluginManager):
|
||||||
# Using Path().resolve() is better than py.path.realpath because
|
# Using Path().resolve() is better than py.path.realpath because
|
||||||
# it resolves to the correct path/drive in case-insensitive file systems (#5792)
|
# it resolves to the correct path/drive in case-insensitive file systems (#5792)
|
||||||
key = Path(str(conftestpath)).resolve()
|
key = Path(str(conftestpath)).resolve()
|
||||||
try:
|
|
||||||
|
with contextlib.suppress(KeyError):
|
||||||
return self._conftestpath2mod[key]
|
return self._conftestpath2mod[key]
|
||||||
except KeyError:
|
|
||||||
pkgpath = conftestpath.pypkgpath()
|
pkgpath = conftestpath.pypkgpath()
|
||||||
if pkgpath is None:
|
if pkgpath is None:
|
||||||
_ensure_removed_sysmodule(conftestpath.purebasename)
|
_ensure_removed_sysmodule(conftestpath.purebasename)
|
||||||
|
|
||||||
try:
|
try:
|
||||||
mod = conftestpath.pyimport()
|
mod = conftestpath.pyimport()
|
||||||
if (
|
if (
|
||||||
|
@ -525,8 +528,8 @@ class PytestPluginManager(PluginManager):
|
||||||
and not self._using_pyargs
|
and not self._using_pyargs
|
||||||
):
|
):
|
||||||
_fail_on_non_top_pytest_plugins(conftestpath, self._confcutdir)
|
_fail_on_non_top_pytest_plugins(conftestpath, self._confcutdir)
|
||||||
except Exception:
|
except Exception as e:
|
||||||
raise ConftestImportFailure(conftestpath, sys.exc_info())
|
raise ConftestImportFailure(conftestpath, sys.exc_info()) from e
|
||||||
|
|
||||||
self._conftest_plugins.add(mod)
|
self._conftest_plugins.add(mod)
|
||||||
self._conftestpath2mod[key] = mod
|
self._conftestpath2mod[key] = mod
|
||||||
|
|
Loading…
Reference in New Issue