11"""Tests for the "lint" subcommand of ni-python-styleguide."""
22
33import itertools
4+ import textwrap
45
56import pytest
67import toml
78
89
910TOO_LONG_LINE = "a_really_long_order = [" + ", " .join (itertools .repeat ('"spam"' , 10 )) + "]\n "
11+ NO_DOC_STRING = textwrap .dedent (
12+ f"""\
13+ def my_method():
14+ assert True
15+ """
16+ )
1017
1118
1219@pytest .fixture
@@ -148,8 +155,8 @@ def test_lint__no_args_lints_subdirs(styleguide_lint, tmp_path):
148155 assert "subdir/spam.py" in result .output .replace ("\\ " , "/" )
149156
150157
151- def test_lint__lignores_venv_by_default (styleguide_lint , tmp_path ):
152- """Test that we exclude ".venv" dir by default."""
158+ def test_lint__ignores_venv_by_default (styleguide_lint , tmp_path ):
159+ """Tests that we exclude ".venv" dir by default."""
153160 (tmp_path / ".venv" ).mkdir ()
154161 (tmp_path / ".venv" / "spam.py" ).write_text (TOO_LONG_LINE )
155162
@@ -158,6 +165,26 @@ def test_lint__lignores_venv_by_default(styleguide_lint, tmp_path):
158165 assert result , result .output
159166
160167
168+ def test_lint__ignores_missing_docstrings_in_tests_dir (styleguide_lint , tmp_path ):
169+ (tmp_path / "tests" / "test_spam" ).mkdir (parents = True )
170+ (tmp_path / "tests" / "test_spam" / "test_spam.py" ).write_text (NO_DOC_STRING )
171+
172+ result = styleguide_lint ()
173+
174+ assert result , result .output
175+
176+
177+ def test_lint__checks_docstrings_in_test_helper_methods (styleguide_lint , tmp_path ):
178+ (tmp_path / "tests" ).mkdir ()
179+ (tmp_path / "tests" / "conftest.py" ).write_text (NO_DOC_STRING )
180+
181+ result = styleguide_lint ()
182+
183+ # D100: Missing docstring in public module
184+ # D103: Missing docstring in public function
185+ assert "D100" and "D103" in result .output , result .output
186+
187+
161188def test_lint__exclude__excludes_file (styleguide_lint_with_options , tmp_path ):
162189 """Test that exclude option excludes a file."""
163190 (tmp_path / "spam.py" ).write_text (TOO_LONG_LINE )
0 commit comments