Skip to content

Commit c93d18b

Browse files
committed
Add argument to fail for warnings
1 parent 7c84f01 commit c93d18b

File tree

2 files changed

+16
-3
lines changed

2 files changed

+16
-3
lines changed

relint.py

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -52,10 +52,16 @@ def parse_args(args):
5252
action='store_true',
5353
help='Analyze content from git diff.'
5454
)
55+
parser.add_argument(
56+
'-W',
57+
'--fail-warnings',
58+
action='store_true',
59+
help='Fail for warnings.'
60+
)
5561
return parser.parse_args(args=args)
5662

5763

58-
def load_config(path):
64+
def load_config(path, fail_warnings):
5965
with open(path) as fs:
6066
for test in yaml.safe_load(fs):
6167
filename = test.get('filename')
@@ -76,7 +82,7 @@ def load_config(path):
7682
hint=test.get('hint'),
7783
file_pattern=file_pattern,
7884
filename=filename,
79-
error=test.get('error', True)
85+
error=test.get('error', True) or fail_warnings
8086
)
8187

8288

@@ -217,7 +223,7 @@ def main(args=sys.argv[1:]):
217223
for path in glob.iglob(glob.escape(file), recursive=True)
218224
}
219225

220-
tests = list(load_config(args.config))
226+
tests = list(load_config(args.config, args.fail_warnings))
221227

222228
matches = chain.from_iterable(
223229
lint_file(path, tests)

test_relint.py

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,13 @@ def test_main_execution(self, mocker, filename):
1616

1717
assert exc_info.value.code == 0
1818

19+
@pytest.mark.parametrize('filename', ['test_relint.py', '[a-b].py', '[b-a].py'])
20+
def test_main_execution(self, mocker, filename):
21+
with pytest.raises(SystemExit) as exc_info:
22+
main(['relint.py', '-W', filename])
23+
24+
assert exc_info.value.code != 0
25+
1926
def test_main_execution_with_diff(self, capsys, mocker, tmpdir):
2027
tmpdir.join('.relint.yml').write(open('.relint.yml').read())
2128
tmpdir.join('dummy.py').write("# TODO do something")

0 commit comments

Comments
 (0)