From b4bd95e668c90157820c994ee194cd0ac4378961 Mon Sep 17 00:00:00 2001 From: Neal Gompa Date: Sep 23 2021 12:41:00 +0000 Subject: tests: Skip style checks when style check tools are not installed We do not necessarily want the test suite to fail when the style check tools are not installed, since that invalidates the usability of unit tests in packaging and other environments where style checking is not important. Signed-off-by: Neal Gompa --- diff --git a/tests/test_style.py b/tests/test_style.py index a00e0a9..50b3907 100644 --- a/tests/test_style.py +++ b/tests/test_style.py @@ -34,7 +34,14 @@ class TestStyle(unittest.TestCase): This test runs flake8 on the code, and will fail if it returns a non-zero exit code. + If flake8 is not installed, this test auto-skips. """ + try: + import flake8 + except ImportError as e: + raise unittest.SkipTest( + "flake8 is not installed, skipping flake8 style check..." + ) # We ignore E712, which disallows non-identity comparisons with True and False # We ignore W503, which disallows line break before binary operator flake8_command = [ @@ -77,7 +84,14 @@ class TestStyle(unittest.TestCase): This test runs black on the code, and will fail if it returns a non-zero exit code. + If black is not installed, this test auto-skips. """ + try: + import black + except ImportError as e: + raise unittest.SkipTest( + "black is not installed, skipping black style check..." + ) black_command = [ sys.executable, "-m",