Skip to content

Commit 129dbed

Browse files
committed
Fix exception causes in config/__init__.py
1 parent 0821c5c commit 129dbed

File tree

1 file changed

+7
-7
lines changed

1 file changed

+7
-7
lines changed

src/_pytest/config/__init__.py

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -641,7 +641,7 @@ def import_plugin(self, modname: str, consider_entry_points: bool = False) -> No
641641
except ImportError as e:
642642
raise ImportError(
643643
'Error importing plugin "{}": {}'.format(modname, str(e.args[0]))
644-
).with_traceback(e.__traceback__)
644+
).with_traceback(e.__traceback__) from e
645645

646646
except Skipped as e:
647647
from _pytest.warnings import _issue_warning_captured
@@ -1130,8 +1130,8 @@ def getini(self, name: str):
11301130
def _getini(self, name: str) -> Any:
11311131
try:
11321132
description, type, default = self._parser._inidict[name]
1133-
except KeyError:
1134-
raise ValueError("unknown configuration value: {!r}".format(name))
1133+
except KeyError as e:
1134+
raise ValueError("unknown configuration value: {!r}".format(name)) from e
11351135
override_value = self._get_override_ini_value(name)
11361136
if override_value is None:
11371137
try:
@@ -1197,12 +1197,12 @@ def _get_override_ini_value(self, name: str) -> Optional[str]:
11971197
for ini_config in self._override_ini:
11981198
try:
11991199
key, user_ini_value = ini_config.split("=", 1)
1200-
except ValueError:
1200+
except ValueError as e:
12011201
raise UsageError(
12021202
"-o/--override-ini expects option=value style (got: {!r}).".format(
12031203
ini_config
12041204
)
1205-
)
1205+
) from e
12061206
else:
12071207
if key == name:
12081208
value = user_ini_value
@@ -1223,14 +1223,14 @@ def getoption(self, name: str, default=notset, skip: bool = False):
12231223
if val is None and skip:
12241224
raise AttributeError(name)
12251225
return val
1226-
except AttributeError:
1226+
except AttributeError as e:
12271227
if default is not notset:
12281228
return default
12291229
if skip:
12301230
import pytest
12311231

12321232
pytest.skip("no {!r} option found".format(name))
1233-
raise ValueError("no option named {!r}".format(name))
1233+
raise ValueError("no option named {!r}".format(name)) from e
12341234

12351235
def getvalue(self, name, path=None):
12361236
""" (deprecated, use getoption()) """

0 commit comments

Comments
 (0)