From 24f36f15f3feb353e8207052869e3c5600f46094 Mon Sep 17 00:00:00 2001 From: Blair Bonnett Date: Tue, 8 Sep 2020 12:08:04 +0200 Subject: [PATCH] Don't override TOML paths with empty CLI paths. The paths CLI argument did not use the default=missing sentinel, and so returned an empty list if no paths were given to the CLI. This meant any paths configured in pyproject.toml were overridden with an empty list, making the path= setting useless. Adding the sentinel to the CLI fixes this behaviour. A regression test is also added to make sure TOML paths are used if no CLI paths are given. --- tests/test_config.py | 21 +++++++++++++++++++++ vulture/config.py | 1 + 2 files changed, 22 insertions(+) diff --git a/tests/test_config.py b/tests/test_config.py index 4a9a9075..7a4902d1 100644 --- a/tests/test_config.py +++ b/tests/test_config.py @@ -147,6 +147,27 @@ def test_config_merging_missing(): assert result["ignore_names"] == ["name1"] +def test_config_merging_toml_paths_only(): + """ + If we have paths in the TOML but not on the CLI, the TOML paths should be + used. + """ + toml = StringIO( + dedent( + """\ + [tool.vulture] + paths = ["path1", "path2"] + """ + ) + ) + cliargs = [ + "--exclude=test_*.py" + ] + result = make_config(cliargs, toml) + assert result["paths"] == ["path1", "path2"] + assert result["exclude"] == ["test_*.py"] + + def test_invalid_config_options_output(): """ If the config file contains unknown options we want to abort. diff --git a/vulture/config.py b/vulture/config.py index 45ae0c38..a9a222e8 100644 --- a/vulture/config.py +++ b/vulture/config.py @@ -100,6 +100,7 @@ def csv(exclude): "paths", nargs="*", metavar="PATH", + default=missing, help="Paths may be Python files or directories. For each directory" " Vulture analyzes all contained *.py files.", )