From 11180856f651b896441254ac29b9b82807b40660 Mon Sep 17 00:00:00 2001 From: Jair Henrique Date: Thu, 14 May 2020 14:17:56 -0300 Subject: [PATCH] Use suppress instead of try/except/else --- runtests.py | 26 +++++++++----------------- 1 file changed, 9 insertions(+), 17 deletions(-) diff --git a/runtests.py b/runtests.py index 19513cdbf..a3af479e0 100755 --- a/runtests.py +++ b/runtests.py @@ -1,6 +1,7 @@ #! /usr/bin/env python3 import subprocess import sys +from contextlib import suppress import pytest @@ -54,27 +55,21 @@ def is_class(string): if __name__ == "__main__": - try: + run_flake8 = True + run_isort = True + with suppress(ValueError): sys.argv.remove('--nolint') - except ValueError: - run_flake8 = True - run_isort = True - else: run_flake8 = False run_isort = False - try: + run_tests = True + with suppress(ValueError): sys.argv.remove('--lintonly') - except ValueError: - run_tests = True - else: run_tests = False - try: + style = 'default' + with suppress(ValueError): sys.argv.remove('--fast') - except ValueError: - style = 'default' - else: style = 'fast' run_flake8 = False run_isort = False @@ -83,11 +78,8 @@ if __name__ == "__main__": pytest_args = sys.argv[1:] first_arg = pytest_args[0] - try: + with suppress(ValueError): pytest_args.remove('--coverage') - except ValueError: - pass - else: pytest_args = [ '--cov', '.', '--cov-report', 'xml',