From e1a4b4edd2b3931240c9df81c7bd5b45e30e4782 Mon Sep 17 00:00:00 2001 From: Taneli Hukkinen <3275109+hukkin@users.noreply.github.com> Date: Tue, 6 Jul 2021 13:10:44 +0300 Subject: [PATCH] Convert `TOMLDecodeError` to `UsageError` --- src/_pytest/config/findpaths.py | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/src/_pytest/config/findpaths.py b/src/_pytest/config/findpaths.py index 62214f8d9..89ade5f23 100644 --- a/src/_pytest/config/findpaths.py +++ b/src/_pytest/config/findpaths.py @@ -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: