From e6cf29673fa572e14c33289f8e3ac75beae779fa Mon Sep 17 00:00:00 2001 From: Scott K Logan Date: Sat, 2 Sep 2023 18:26:14 -0500 Subject: [PATCH] Add markers to linter tests, move linter imports (#576) Test markers can be used to easily (de-)select tests, and colcon exposes mechanisms to do so. Linters are a category of tests that are commonly called out. Additionally, if we move the imports for some of our single-purpose tests into the test function, we can avoid installing the linter dependencies entirely. This is a common case in platform packaging, where linter errors are not actionable and the dependencies are not typically installed. --- setup.cfg | 3 +++ test/spell_check.words | 1 + test/test_copyright_license.py | 3 +++ test/test_flake8.py | 15 ++++++++------- test/test_spell_check.py | 11 +++++++---- 5 files changed, 22 insertions(+), 11 deletions(-) diff --git a/setup.cfg b/setup.cfg index 855b91d2..407add80 100644 --- a/setup.cfg +++ b/setup.cfg @@ -77,6 +77,9 @@ filterwarnings = # Suppress resource warnings pending investigation always::ResourceWarning junit_suite_name = colcon-core +markers = + flake8 + linter python_classes = !TestFailure [options.entry_points] diff --git a/test/spell_check.words b/test/spell_check.words index 6539aa60..a1cb3d99 100644 --- a/test/spell_check.words +++ b/test/spell_check.words @@ -53,6 +53,7 @@ junit levelname libexec lineno +linter linux lstrip mkdtemp diff --git a/test/test_copyright_license.py b/test/test_copyright_license.py index 7b4ffb38..b428f4d3 100644 --- a/test/test_copyright_license.py +++ b/test/test_copyright_license.py @@ -4,7 +4,10 @@ from pathlib import Path import sys +import pytest + +@pytest.mark.linter def test_copyright_license(): missing = check_files([ Path(__file__).parents[1], diff --git a/test/test_flake8.py b/test/test_flake8.py index 4fdd553a..c7214ed6 100644 --- a/test/test_flake8.py +++ b/test/test_flake8.py @@ -5,19 +5,20 @@ from pathlib import Path import sys -from flake8 import LOG -from flake8.api.legacy import get_style_guide -from pydocstyle.utils import log +import pytest -# avoid debug / info / warning messages from flake8 internals -LOG.setLevel(logging.ERROR) +@pytest.mark.flake8 +@pytest.mark.linter +def test_flake8(): + from flake8.api.legacy import get_style_guide + # avoid debug / info / warning messages from flake8 internals + logging.getLogger('flake8').setLevel(logging.ERROR) -def test_flake8(): # for some reason the pydocstyle logger changes to an effective level of 1 # set higher level to prevent the output to be flooded with debug messages - log.setLevel(logging.WARNING) + logging.getLogger('pydocstyle').setLevel(logging.WARNING) style_guide = get_style_guide( extend_ignore=['D100', 'D104'], diff --git a/test/test_spell_check.py b/test/test_spell_check.py index d6718d14..10e5725d 100644 --- a/test/test_spell_check.py +++ b/test/test_spell_check.py @@ -4,10 +4,6 @@ from pathlib import Path import pytest -from scspell import Report -from scspell import SCSPELL_BUILTIN_DICT -from scspell import spell_check - spell_check_words_path = Path(__file__).parent / 'spell_check.words' @@ -18,7 +14,12 @@ def known_words(): return spell_check_words_path.read_text().splitlines() +@pytest.mark.linter def test_spell_check(known_words): + from scspell import Report + from scspell import SCSPELL_BUILTIN_DICT + from scspell import spell_check + source_filenames = [ Path(__file__).parents[1] / 'bin' / 'colcon', Path(__file__).parents[1] / 'setup.py'] + \ @@ -46,11 +47,13 @@ def test_spell_check(known_words): ', '.join(sorted(unused_known_words)) +@pytest.mark.linter def test_spell_check_word_list_order(known_words): assert known_words == sorted(known_words), \ 'The word list should be ordered alphabetically' +@pytest.mark.linter def test_spell_check_word_list_duplicates(known_words): assert len(known_words) == len(set(known_words)), \ 'The word list should not contain duplicates'