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 0bd2d2b
Show file tree
Hide file tree
Showing 6 changed files with 44 additions and 0 deletions.
34 changes: 34 additions & 0 deletions .github/workflows/ci.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,40 @@ jobs:
files: ./coverage.xml
token: ${{ secrets.CODECOV_TOKEN }}

skip-linters:
runs-on: ubuntu-latest
strategy:
fail-fast: false
matrix:
container:
- debian:bookworm-slim
- debian:testing-slim
- debian:unstable-slim
- ubuntu:jammy
- ubuntu:noble
- ubuntu:oracular
container:
image: ${{ matrix.container }}
steps:
- name: Install dependencies
run: >
apt-get update &&
apt-get install --no-install-recommends --yes ca-certificates git
pylint python3 python3-coverage python3-ruamel.yaml
- uses: actions/checkout@v4
- name: Run unit tests
run: |
SKIP_LINTERS=1 python3 -m coverage run -m unittest discover -v
python3 -m coverage xml
- name: Install dependencies for Codecov
run: apt-get install --no-install-recommends --yes curl gpg gpg-agent
- name: Upload coverage to Codecov
uses: codecov/codecov-action@v4
with:
fail_ci_if_error: true
files: ./coverage.xml
token: ${{ secrets.CODECOV_TOKEN }}

system-testing:
runs-on: ubuntu-latest
strategy:
Expand Down
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 0bd2d2b

Please sign in to comment.