Skip to content

Commit 5987251

Browse files
committed
Add a test for invalid TOML file
1 parent 40797de commit 5987251

File tree

1 file changed

+8
-0
lines changed

1 file changed

+8
-0
lines changed

testing/test_findpaths.py

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
from textwrap import dedent
33

44
import pytest
5+
from _pytest.config import UsageError
56
from _pytest.config.findpaths import get_common_ancestor
67
from _pytest.config.findpaths import get_dirs_from_args
78
from _pytest.config.findpaths import load_config_dict_from_file
@@ -52,6 +53,13 @@ def test_unsupported_pytest_section_in_cfg_file(self, tmp_path: Path) -> None:
5253
load_config_dict_from_file(fn)
5354

5455
def test_invalid_toml_file(self, tmp_path: Path) -> None:
56+
"""Invalid .toml files should raise `UsageError`."""
57+
fn = tmp_path / "myconfig.toml"
58+
fn.write_text("]invalid toml[", encoding="utf-8")
59+
with pytest.raises(UsageError):
60+
load_config_dict_from_file(fn)
61+
62+
def test_custom_toml_file(self, tmp_path: Path) -> None:
5563
""".toml files without [tool.pytest.ini_options] are not considered for configuration."""
5664
fn = tmp_path / "myconfig.toml"
5765
fn.write_text(

0 commit comments

Comments
 (0)