Skip to content

Commit

Permalink
test: support skip running linters via env variable
Browse files Browse the repository at this point in the history
Support skip running the linters by setting the environment variable
`SKIP_LINTERS=1`. This flag is useful for distributions.
  • Loading branch information
bdrung committed Aug 1, 2024
1 parent 41e07c2 commit 162d25d
Show file tree
Hide file tree
Showing 5 changed files with 10 additions and 0 deletions.
2 changes: 2 additions & 0 deletions tests/test_black.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@

"""Run black code formatter in check mode."""

import os
import subprocess
import sys
import unittest
Expand All @@ -28,6 +29,7 @@ class BlackTestCase(unittest.TestCase):
source files is provided by the get_source_files() function.
"""

@unittest.skipIf(os.environ.get("SKIP_LINTERS"), "requested via SKIP_LINTERS env variable")
def test_black(self):
"""Test: Run black code formatter on Python source code."""

Expand Down
2 changes: 2 additions & 0 deletions tests/test_flake8.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@

"""Run flake8 check."""

import os
import subprocess
import sys
import unittest
Expand All @@ -29,6 +30,7 @@ class Flake8TestCase(unittest.TestCase):
get_source_files() function.
"""

@unittest.skipIf(os.environ.get("SKIP_LINTERS"), "requested via SKIP_LINTERS env variable")
def test_flake8(self):
"""Test: Run flake8 on Python source code."""
cmd = [sys.executable, "-m", "flake8", "--max-line-length=99"] + get_source_files()
Expand Down
2 changes: 2 additions & 0 deletions tests/test_isort.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@

"""Run isort to check if Python import definitions are sorted."""

import os
import subprocess
import sys
import unittest
Expand All @@ -28,6 +29,7 @@ class IsortTestCase(unittest.TestCase):
is provided by the get_source_files() function.
"""

@unittest.skipIf(os.environ.get("SKIP_LINTERS"), "requested via SKIP_LINTERS env variable")
def test_isort(self):
"""Test: Run isort on Python source code."""

Expand Down
2 changes: 2 additions & 0 deletions tests/test_pylint.py
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,8 @@ def test_pylint(self):
"""Test: Run pylint on Python source code."""

cmd = [sys.executable, "-m", "pylint", "--rcfile=" + CONFIG, "--"] + get_source_files()
if os.environ.get("SKIP_LINTERS"):
cmd.insert(4, "--errors-only")
if unittest_verbosity() >= 2:
sys.stderr.write(f"Running following command:\n{' '.join(cmd)}\n")
with subprocess.Popen(
Expand Down
2 changes: 2 additions & 0 deletions tests/test_shellcheck.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@

"""Run shellcheck on Shell code."""

import os
import subprocess
import sys
import unittest
Expand All @@ -29,6 +30,7 @@ class ShellcheckTestCase(unittest.TestCase):
on Shell source code.
"""

@unittest.skipIf(os.environ.get("SKIP_LINTERS"), "requested via SKIP_LINTERS env variable")
def test_shellcheck(self):
"""Test: Run shellcheck on Shell source code."""
cmd = ["shellcheck"] + [get_path(s) for s in SHELL_SCRIPTS]
Expand Down

0 comments on commit 162d25d

Please sign in to comment.