From 5987251407d210bd30484081447d6a20f4ac7e0b Mon Sep 17 00:00:00 2001 From: Taneli Hukkinen <3275109+hukkin@users.noreply.github.com> Date: Tue, 6 Jul 2021 16:53:32 +0300 Subject: [PATCH] Add a test for invalid TOML file --- testing/test_findpaths.py | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/testing/test_findpaths.py b/testing/test_findpaths.py index 3c876d96b..3a2917261 100644 --- a/testing/test_findpaths.py +++ b/testing/test_findpaths.py @@ -2,6 +2,7 @@ from pathlib import Path from textwrap import dedent import pytest +from _pytest.config import UsageError from _pytest.config.findpaths import get_common_ancestor from _pytest.config.findpaths import get_dirs_from_args from _pytest.config.findpaths import load_config_dict_from_file @@ -52,6 +53,13 @@ class TestLoadConfigDictFromFile: load_config_dict_from_file(fn) def test_invalid_toml_file(self, tmp_path: Path) -> None: + """Invalid .toml files should raise `UsageError`.""" + fn = tmp_path / "myconfig.toml" + fn.write_text("]invalid toml[", encoding="utf-8") + with pytest.raises(UsageError): + load_config_dict_from_file(fn) + + def test_custom_toml_file(self, tmp_path: Path) -> None: """.toml files without [tool.pytest.ini_options] are not considered for configuration.""" fn = tmp_path / "myconfig.toml" fn.write_text(