Convert `TOMLDecodeError` to `UsageError`

This commit is contained in:
Taneli Hukkinen 2021-07-06 13:10:44 +03:00
parent e942b12b94
commit e1a4b4edd2
1 changed files with 5 additions and 1 deletions

View File

@ -66,7 +66,11 @@ def load_config_dict_from_file(
elif filepath.suffix == ".toml":
import tomli
config = tomli.loads(filepath.read_text(encoding="utf-8"))
toml_text = filepath.read_text(encoding="utf-8")
try:
config = tomli.loads(toml_text)
except tomli.TOMLDecodeError as exc:
raise UsageError(str(exc)) from exc
result = config.get("tool", {}).get("pytest", {}).get("ini_options", None)
if result is not None: