Skip to content

Commit b7e041f

Browse files
authored
fix: ensure that configuration files are loaded in the order (robocop.toml > robot.toml > pyproject.toml) (#1729)
1 parent 2b07350 commit b7e041f

6 files changed

Lines changed: 32 additions & 4 deletions

File tree

docs/configuration/index.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -25,11 +25,11 @@ Robocop uses a configuration file closest to the source, which allows multiple c
2525
that apply to the entire execution (such as ``--exit-zero`` or report settings) are exclusively read from the top-level
2626
configuration file.
2727

28-
When looking for the configuration file, Robocop searches either for:
28+
When looking for the configuration file, Robocop searches in the following order:
2929

30+
- ``robocop.toml``
31+
- ``robot.toml``
3032
- ``pyproject.toml``
31-
- or ``robocop.toml``
32-
- or ``robot.toml``
3333

3434
It will visit parent directories until it finds root of the project determined by existence of ``.git`` directory.
3535
This behaviour can be disabled with ``--ignore-git-dir``.

src/robocop/config/manager.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@
1616
if TYPE_CHECKING:
1717
from collections.abc import Generator, Sequence
1818

19-
CONFIG_NAMES = frozenset(("robocop.toml", "pyproject.toml", "robot.toml"))
19+
CONFIG_NAMES = ("robocop.toml", "robot.toml", "pyproject.toml")
2020

2121

2222
class GitIgnoreResolver:

tests/config/test_config_manager.py

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -572,6 +572,28 @@ def test_extend_select_formatter(self, tmp_path, overwrite_config):
572572
# Assert
573573
assert "IndentNestedKeywords" in resolved_config.formatters
574574

575+
def test_config_order(self, tmp_path):
576+
# Single file
577+
config_file = tmp_path / "pyproject.toml"
578+
config_file.write_text("[tool.robocop]\nverbose = true\n", encoding="utf-8")
579+
with working_directory(tmp_path):
580+
config_manager = ConfigManager()
581+
assert config_manager.default_config.config_source.endswith("pyproject.toml")
582+
583+
# Two files
584+
config_file = tmp_path / "robot.toml"
585+
config_file.write_text("[tool.robocop]\nverbose = true\n", encoding="utf-8")
586+
with working_directory(tmp_path):
587+
config_manager = ConfigManager()
588+
assert config_manager.default_config.config_source.endswith("robot.toml")
589+
590+
# Three files
591+
config_file = tmp_path / "robocop.toml"
592+
config_file.write_text("[tool.robocop]\nverbose = true\n", encoding="utf-8")
593+
with working_directory(tmp_path):
594+
config_manager = ConfigManager()
595+
assert config_manager.default_config.config_source.endswith("robocop.toml")
596+
575597

576598
class TestCacheConfigOverride:
577599
"""Test that CLI cache options properly override config file cache settings."""
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
[tool.robocop]
2+
verbose = false
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
[tool.robocop]
2+
verbose = true
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
[tool.robot.format]
2+
diff = true

0 commit comments

Comments
 (0)