Skip to content

Commit 210c5e2

Browse files
mnarusmshafer-NI
authored andcommitted
Ignore missing docstrings in methods in "tests" dir "test_*.py" (#120)
* create a failing test * Add ignore for tests docstrings * Add check for tests\* - not test_*.py * make test pass
1 parent 14c63e6 commit 210c5e2

File tree

2 files changed

+32
-2
lines changed

2 files changed

+32
-2
lines changed

ni_python_styleguide/config.ini

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -80,6 +80,9 @@ ignore =
8080
# flake8-import-order
8181
I101 # The names in your from import are in the wrong order. (Enforced by E401)
8282

83+
# We want to ignore missing docstrings in test methods as they are self documenting
84+
per-file-ignores= tests/**/test_*.py:D100,D103
85+
8386
# Flake8 includes mccabe by default.
8487
# We have yet to evaluate it, so ignore the errors for now
8588
extend-ignore=C90

tests/test_cli/test_lint.py

Lines changed: 29 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,19 @@
11
"""Tests for the "lint" subcommand of ni-python-styleguide."""
22

33
import itertools
4+
import textwrap
45

56
import pytest
67
import toml
78

89

910
TOO_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+
161188
def 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

Comments
 (0)