diff --git a/setup.cfg b/setup.cfg index 1628050..5d32449 100644 --- a/setup.cfg +++ b/setup.cfg @@ -47,6 +47,9 @@ test = [tool:pytest] junit_suite_name = template-package +markers = + flake8 + linter [options.entry_points] diff --git a/test/spell_check.words b/test/spell_check.words index 52c70fc..577de28 100644 --- a/test/spell_check.words +++ b/test/spell_check.words @@ -1,6 +1,8 @@ apache iterdir +linter pathlib +pydocstyle pytest scspell setuptools diff --git a/test/test_copyright_license.py b/test/test_copyright_license.py index e701370..dffe460 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]]) assert not len(missing), \ @@ -25,8 +28,8 @@ def check_files(paths): if not content: continue lines = content.splitlines() - has_copyright = \ - any(line for line in lines if line.startswith('# Copyright')) + has_copyright = any(filter( + lambda line: line.startswith('# Copyright'), lines)) has_license = \ '# Licensed under the Apache License, Version 2.0' in lines if not has_copyright or not has_license: diff --git a/test/test_flake8.py b/test/test_flake8.py index 3792f47..cd42005 100644 --- a/test/test_flake8.py +++ b/test/test_flake8.py @@ -5,15 +5,21 @@ from pathlib import Path import sys -from flake8 import LOG -from flake8.api.legacy import get_style_guide +import pytest -# avoid debug and info messages from flake8 internals -LOG.setLevel(logging.WARN) +@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) + + # 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 + logging.getLogger('pydocstyle').setLevel(logging.WARNING) -def test_flake8(): style_guide = get_style_guide( extend_ignore=['D100', 'D104'], show_source=True, @@ -43,9 +49,6 @@ def test_flake8(): if report_tests.total_errors: report_tests._application.formatter.show_statistics( report_tests._stats) - print( - 'flake8 reported {total_errors} errors' - .format_map(locals()), file=sys.stderr) + print(f'flake8 reported {total_errors} errors', file=sys.stderr) - assert not total_errors, \ - 'flake8 reported {total_errors} errors'.format_map(locals()) + assert not total_errors, f'flake8 reported {total_errors} errors' diff --git a/test/test_spell_check.py b/test/test_spell_check.py index f016c1b..7c1559b 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] / 'setup.py'] + \ list( (Path(__file__).parents[1] / 'template_package') @@ -36,21 +37,23 @@ def test_spell_check(known_words): unknown_word_count = len(report.unknown_words) assert unknown_word_count == 0, \ - 'Found {unknown_word_count} unknown words: '.format_map(locals()) + \ + f'Found {unknown_word_count} unknown words: ' + \ ', '.join(sorted(report.unknown_words)) unused_known_words = set(known_words) - report.found_known_words unused_known_word_count = len(unused_known_words) assert unused_known_word_count == 0, \ - '{unused_known_word_count} words in the word list are not used: ' \ - .format_map(locals()) + ', '.join(sorted(unused_known_words)) + f'{unused_known_word_count} words in the word list are not used: ' + \ + ', '.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'