assert-pytest-class-holds-state 20260907154656__py3-none-any.whl
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- assert_pytest_class_holds_state/__init__.py +0 -0
- assert_pytest_class_holds_state/__main__.py +3 -0
- assert_pytest_class_holds_state/cli.py +277 -0
- assert_pytest_class_holds_state/py.typed +0 -0
- assert_pytest_class_holds_state/scanner.py +88 -0
- assert_pytest_class_holds_state-20260907154656.dist-info/METADATA +157 -0
- assert_pytest_class_holds_state-20260907154656.dist-info/RECORD +11 -0
- assert_pytest_class_holds_state-20260907154656.dist-info/WHEEL +5 -0
- assert_pytest_class_holds_state-20260907154656.dist-info/entry_points.txt +2 -0
- assert_pytest_class_holds_state-20260907154656.dist-info/licenses/LICENSE.txt +190 -0
- assert_pytest_class_holds_state-20260907154656.dist-info/top_level.txt +1 -0
|
File without changes
|
|
@@ -0,0 +1,277 @@
|
|
|
1
|
+
from __future__ import annotations
|
|
2
|
+
|
|
3
|
+
import argparse
|
|
4
|
+
import fnmatch
|
|
5
|
+
import glob
|
|
6
|
+
import os
|
|
7
|
+
import sys
|
|
8
|
+
from dataclasses import dataclass
|
|
9
|
+
from typing import TYPE_CHECKING
|
|
10
|
+
|
|
11
|
+
from .scanner import Finding, is_test_file, scan_file
|
|
12
|
+
|
|
13
|
+
if TYPE_CHECKING:
|
|
14
|
+
from collections.abc import Sequence
|
|
15
|
+
|
|
16
|
+
EXIT_SUCCESS = 0
|
|
17
|
+
EXIT_FINDINGS = 1
|
|
18
|
+
EXIT_ERROR = 2
|
|
19
|
+
|
|
20
|
+
|
|
21
|
+
@dataclass
|
|
22
|
+
class ScanResult:
|
|
23
|
+
findings: list[Finding]
|
|
24
|
+
files_scanned: int
|
|
25
|
+
had_error: bool
|
|
26
|
+
|
|
27
|
+
|
|
28
|
+
def create_parser() -> argparse.ArgumentParser:
|
|
29
|
+
parser = argparse.ArgumentParser(
|
|
30
|
+
prog="assert-pytest-class-holds-state",
|
|
31
|
+
description=(
|
|
32
|
+
"Assert that every pytest class holds a fixture, an attribute, "
|
|
33
|
+
"a helper or a base."
|
|
34
|
+
),
|
|
35
|
+
)
|
|
36
|
+
|
|
37
|
+
parser.add_argument(
|
|
38
|
+
"files",
|
|
39
|
+
nargs="+",
|
|
40
|
+
metavar="FILE",
|
|
41
|
+
help=(
|
|
42
|
+
"One or more file paths, directory paths, or glob patterns to scan. "
|
|
43
|
+
"Directories are scanned recursively for test files (test_*.py, *_test.py)."
|
|
44
|
+
),
|
|
45
|
+
)
|
|
46
|
+
|
|
47
|
+
parser.add_argument(
|
|
48
|
+
"--exclude",
|
|
49
|
+
metavar="PATTERNS",
|
|
50
|
+
help="Comma-separated glob patterns to exclude files.",
|
|
51
|
+
)
|
|
52
|
+
|
|
53
|
+
output_group = parser.add_mutually_exclusive_group()
|
|
54
|
+
output_group.add_argument(
|
|
55
|
+
"--quiet",
|
|
56
|
+
action="store_true",
|
|
57
|
+
help="Suppress all output. Exit code indicates success (0) or findings (1).",
|
|
58
|
+
)
|
|
59
|
+
output_group.add_argument(
|
|
60
|
+
"--count",
|
|
61
|
+
action="store_true",
|
|
62
|
+
help="Output only the count of findings.",
|
|
63
|
+
)
|
|
64
|
+
output_group.add_argument(
|
|
65
|
+
"--verbose",
|
|
66
|
+
action="store_true",
|
|
67
|
+
help="Show detailed processing information.",
|
|
68
|
+
)
|
|
69
|
+
|
|
70
|
+
behavior_group = parser.add_mutually_exclusive_group()
|
|
71
|
+
behavior_group.add_argument(
|
|
72
|
+
"--fail-fast",
|
|
73
|
+
action="store_true",
|
|
74
|
+
help="Exit immediately after finding the first issue.",
|
|
75
|
+
)
|
|
76
|
+
behavior_group.add_argument(
|
|
77
|
+
"--warn-only",
|
|
78
|
+
action="store_true",
|
|
79
|
+
help="Always exit with code 0, even if findings exist.",
|
|
80
|
+
)
|
|
81
|
+
|
|
82
|
+
return parser
|
|
83
|
+
|
|
84
|
+
|
|
85
|
+
def parse_patterns(patterns_str: str | None) -> list[str]:
|
|
86
|
+
if not patterns_str:
|
|
87
|
+
return []
|
|
88
|
+
return [p.strip() for p in patterns_str.split(",") if p.strip()]
|
|
89
|
+
|
|
90
|
+
|
|
91
|
+
def _is_glob_pattern(path: str) -> bool:
|
|
92
|
+
return any(c in path for c in ("*", "?", "["))
|
|
93
|
+
|
|
94
|
+
|
|
95
|
+
def _expand_glob(pattern: str) -> tuple[list[str], bool]:
|
|
96
|
+
matched = glob.glob(pattern, recursive=True, include_hidden=True)
|
|
97
|
+
files = []
|
|
98
|
+
for path in matched:
|
|
99
|
+
if os.path.isfile(path):
|
|
100
|
+
files.append(path)
|
|
101
|
+
elif os.path.isdir(path):
|
|
102
|
+
files.extend(_expand_directory(path))
|
|
103
|
+
return (files, bool(matched))
|
|
104
|
+
|
|
105
|
+
|
|
106
|
+
def _expand_directory(directory: str) -> list[str]:
|
|
107
|
+
files = []
|
|
108
|
+
for root, dirs, filenames in os.walk(directory):
|
|
109
|
+
dirs[:] = [d for d in dirs if not d.startswith(".")]
|
|
110
|
+
|
|
111
|
+
for filename in filenames:
|
|
112
|
+
if filename.endswith(".py"):
|
|
113
|
+
filepath = os.path.join(root, filename)
|
|
114
|
+
if is_test_file(filepath):
|
|
115
|
+
files.append(filepath)
|
|
116
|
+
return files
|
|
117
|
+
|
|
118
|
+
|
|
119
|
+
def _iter_files(paths: Sequence[str]) -> tuple[list[str], list[str]]:
|
|
120
|
+
files: list[str] = []
|
|
121
|
+
missing: list[str] = []
|
|
122
|
+
|
|
123
|
+
for path in paths:
|
|
124
|
+
if _is_glob_pattern(path):
|
|
125
|
+
matched_files, found = _expand_glob(path)
|
|
126
|
+
if found:
|
|
127
|
+
files.extend(matched_files)
|
|
128
|
+
else:
|
|
129
|
+
missing.append(path)
|
|
130
|
+
elif os.path.isfile(path):
|
|
131
|
+
files.append(path)
|
|
132
|
+
elif os.path.isdir(path):
|
|
133
|
+
files.extend(_expand_directory(path))
|
|
134
|
+
else:
|
|
135
|
+
missing.append(path)
|
|
136
|
+
|
|
137
|
+
seen: set[str] = set()
|
|
138
|
+
unique_files: list[str] = []
|
|
139
|
+
for f in files:
|
|
140
|
+
normalized = os.path.normpath(f)
|
|
141
|
+
if normalized not in seen:
|
|
142
|
+
seen.add(normalized)
|
|
143
|
+
unique_files.append(f)
|
|
144
|
+
|
|
145
|
+
return (unique_files, missing)
|
|
146
|
+
|
|
147
|
+
|
|
148
|
+
def _should_skip_file(path: str, exclude_patterns: list[str]) -> bool:
|
|
149
|
+
if not exclude_patterns:
|
|
150
|
+
return False
|
|
151
|
+
|
|
152
|
+
for pattern in exclude_patterns:
|
|
153
|
+
if fnmatch.fnmatch(path, pattern):
|
|
154
|
+
return True
|
|
155
|
+
if fnmatch.fnmatch(os.path.basename(path), pattern):
|
|
156
|
+
return True
|
|
157
|
+
return False
|
|
158
|
+
|
|
159
|
+
|
|
160
|
+
def process_files(
|
|
161
|
+
files: list[str],
|
|
162
|
+
exclude_patterns: list[str],
|
|
163
|
+
verbose: bool = False,
|
|
164
|
+
fail_fast: bool = False,
|
|
165
|
+
) -> ScanResult:
|
|
166
|
+
findings: list[Finding] = []
|
|
167
|
+
files_scanned = 0
|
|
168
|
+
had_error = False
|
|
169
|
+
|
|
170
|
+
for path in sorted(files):
|
|
171
|
+
if not path.endswith(".py"):
|
|
172
|
+
continue
|
|
173
|
+
|
|
174
|
+
if not is_test_file(path):
|
|
175
|
+
continue
|
|
176
|
+
|
|
177
|
+
if _should_skip_file(path, exclude_patterns):
|
|
178
|
+
if verbose:
|
|
179
|
+
print(f"Skipping (excluded): {path}")
|
|
180
|
+
continue
|
|
181
|
+
|
|
182
|
+
if verbose:
|
|
183
|
+
print(f"Scanning: {path}")
|
|
184
|
+
|
|
185
|
+
try:
|
|
186
|
+
with open(path, encoding="utf-8") as f:
|
|
187
|
+
content = f.read()
|
|
188
|
+
except OSError as e:
|
|
189
|
+
print(f"Error reading {path}: {e}", file=sys.stderr)
|
|
190
|
+
had_error = True
|
|
191
|
+
continue
|
|
192
|
+
|
|
193
|
+
try:
|
|
194
|
+
file_findings = scan_file(path, content)
|
|
195
|
+
except SyntaxError as e:
|
|
196
|
+
print(f"Syntax error in {path}: {e}", file=sys.stderr)
|
|
197
|
+
had_error = True
|
|
198
|
+
continue
|
|
199
|
+
|
|
200
|
+
files_scanned += 1
|
|
201
|
+
findings.extend(file_findings)
|
|
202
|
+
|
|
203
|
+
if file_findings and verbose:
|
|
204
|
+
for finding in file_findings:
|
|
205
|
+
print(f" Found: {finding}")
|
|
206
|
+
|
|
207
|
+
if findings and fail_fast:
|
|
208
|
+
break
|
|
209
|
+
|
|
210
|
+
return ScanResult(
|
|
211
|
+
findings=findings,
|
|
212
|
+
files_scanned=files_scanned,
|
|
213
|
+
had_error=had_error,
|
|
214
|
+
)
|
|
215
|
+
|
|
216
|
+
|
|
217
|
+
def output_findings(
|
|
218
|
+
findings: list[Finding],
|
|
219
|
+
count_mode: bool = False,
|
|
220
|
+
) -> None:
|
|
221
|
+
if count_mode:
|
|
222
|
+
print(len(findings))
|
|
223
|
+
else:
|
|
224
|
+
for finding in findings:
|
|
225
|
+
print(finding)
|
|
226
|
+
|
|
227
|
+
|
|
228
|
+
def determine_exit_code(result: ScanResult, warn_only: bool = False) -> int:
|
|
229
|
+
if warn_only:
|
|
230
|
+
return EXIT_SUCCESS
|
|
231
|
+
if result.findings:
|
|
232
|
+
return EXIT_FINDINGS
|
|
233
|
+
if result.had_error:
|
|
234
|
+
return EXIT_ERROR
|
|
235
|
+
return EXIT_SUCCESS
|
|
236
|
+
|
|
237
|
+
|
|
238
|
+
def main(argv: Sequence[str] | None = None) -> None:
|
|
239
|
+
parser = create_parser()
|
|
240
|
+
args = parser.parse_args(argv)
|
|
241
|
+
|
|
242
|
+
exclude_patterns = parse_patterns(args.exclude)
|
|
243
|
+
|
|
244
|
+
files, missing = _iter_files(args.files)
|
|
245
|
+
|
|
246
|
+
for path in missing:
|
|
247
|
+
print(f"Error: Path not found: {path}", file=sys.stderr)
|
|
248
|
+
|
|
249
|
+
if not files and missing:
|
|
250
|
+
sys.exit(EXIT_ERROR)
|
|
251
|
+
|
|
252
|
+
if args.verbose:
|
|
253
|
+
print(f"Scanning {len(files)} file(s) for pytest classes...")
|
|
254
|
+
if exclude_patterns:
|
|
255
|
+
print(f"Excluding patterns: {', '.join(exclude_patterns)}")
|
|
256
|
+
print()
|
|
257
|
+
|
|
258
|
+
result = process_files(
|
|
259
|
+
files=files,
|
|
260
|
+
exclude_patterns=exclude_patterns,
|
|
261
|
+
verbose=args.verbose,
|
|
262
|
+
fail_fast=args.fail_fast,
|
|
263
|
+
)
|
|
264
|
+
|
|
265
|
+
if missing:
|
|
266
|
+
result.had_error = True
|
|
267
|
+
|
|
268
|
+
if args.verbose:
|
|
269
|
+
print()
|
|
270
|
+
print(f"Files scanned: {result.files_scanned}")
|
|
271
|
+
print(f"Findings: {len(result.findings)}")
|
|
272
|
+
if result.had_error:
|
|
273
|
+
print("Errors occurred during scanning.")
|
|
274
|
+
elif not args.quiet:
|
|
275
|
+
output_findings(result.findings, args.count)
|
|
276
|
+
|
|
277
|
+
sys.exit(determine_exit_code(result, args.warn_only))
|
|
File without changes
|
|
@@ -0,0 +1,88 @@
|
|
|
1
|
+
from __future__ import annotations
|
|
2
|
+
|
|
3
|
+
import ast
|
|
4
|
+
import os
|
|
5
|
+
from dataclasses import dataclass
|
|
6
|
+
|
|
7
|
+
MESSAGE = "the test methods belong at module level"
|
|
8
|
+
|
|
9
|
+
FUNCTIONS = (ast.FunctionDef, ast.AsyncFunctionDef)
|
|
10
|
+
ASSIGNMENTS = (ast.Assign, ast.AnnAssign, ast.AugAssign)
|
|
11
|
+
|
|
12
|
+
|
|
13
|
+
@dataclass(frozen=True)
|
|
14
|
+
class Finding:
|
|
15
|
+
path: str
|
|
16
|
+
line_number: int
|
|
17
|
+
class_name: str
|
|
18
|
+
|
|
19
|
+
def __str__(self) -> str:
|
|
20
|
+
return f"{self.path}:{self.line_number}:{self.class_name}: {MESSAGE}"
|
|
21
|
+
|
|
22
|
+
|
|
23
|
+
def is_test_class(name: str) -> bool:
|
|
24
|
+
return name.startswith("Test")
|
|
25
|
+
|
|
26
|
+
|
|
27
|
+
def is_test_file(path: str) -> bool:
|
|
28
|
+
basename = os.path.basename(path)
|
|
29
|
+
return basename.startswith("test_") or basename.endswith("_test.py")
|
|
30
|
+
|
|
31
|
+
|
|
32
|
+
def _is_fixture(decorator: ast.expr) -> bool:
|
|
33
|
+
node = decorator.func if isinstance(decorator, ast.Call) else decorator
|
|
34
|
+
if isinstance(node, ast.Attribute):
|
|
35
|
+
return node.attr == "fixture"
|
|
36
|
+
return isinstance(node, ast.Name) and node.id == "fixture"
|
|
37
|
+
|
|
38
|
+
|
|
39
|
+
def _is_test_method(node: ast.FunctionDef | ast.AsyncFunctionDef) -> bool:
|
|
40
|
+
if any(_is_fixture(decorator) for decorator in node.decorator_list):
|
|
41
|
+
return False
|
|
42
|
+
return node.name.startswith("test")
|
|
43
|
+
|
|
44
|
+
|
|
45
|
+
def _holds_an_assignment(node: ast.ClassDef) -> bool:
|
|
46
|
+
return any(isinstance(stmt, ASSIGNMENTS) for stmt in node.body)
|
|
47
|
+
|
|
48
|
+
|
|
49
|
+
def _holds_a_helper(node: ast.ClassDef) -> bool:
|
|
50
|
+
return any(
|
|
51
|
+
not _is_test_method(stmt)
|
|
52
|
+
for stmt in node.body
|
|
53
|
+
if isinstance(stmt, FUNCTIONS)
|
|
54
|
+
)
|
|
55
|
+
|
|
56
|
+
|
|
57
|
+
def holds_state(node: ast.ClassDef) -> bool:
|
|
58
|
+
return bool(
|
|
59
|
+
node.bases
|
|
60
|
+
or node.keywords
|
|
61
|
+
or node.decorator_list
|
|
62
|
+
or _holds_an_assignment(node)
|
|
63
|
+
or _holds_a_helper(node)
|
|
64
|
+
)
|
|
65
|
+
|
|
66
|
+
|
|
67
|
+
class NamespaceFinder(ast.NodeVisitor):
|
|
68
|
+
def __init__(self, path: str) -> None:
|
|
69
|
+
self.path = path
|
|
70
|
+
self.findings: list[Finding] = []
|
|
71
|
+
|
|
72
|
+
def generic_visit(self, node: ast.AST) -> None:
|
|
73
|
+
if isinstance(node, FUNCTIONS):
|
|
74
|
+
return
|
|
75
|
+
if isinstance(node, ast.ClassDef):
|
|
76
|
+
self._check_class(node)
|
|
77
|
+
super().generic_visit(node)
|
|
78
|
+
|
|
79
|
+
def _check_class(self, node: ast.ClassDef) -> None:
|
|
80
|
+
if is_test_class(node.name) and not holds_state(node):
|
|
81
|
+
self.findings.append(Finding(self.path, node.lineno, node.name))
|
|
82
|
+
|
|
83
|
+
|
|
84
|
+
def scan_file(path: str, content: str) -> list[Finding]:
|
|
85
|
+
tree = ast.parse(content, filename=path)
|
|
86
|
+
finder = NamespaceFinder(path)
|
|
87
|
+
finder.visit(tree)
|
|
88
|
+
return finder.findings
|
|
@@ -0,0 +1,157 @@
|
|
|
1
|
+
Metadata-Version: 2.4
|
|
2
|
+
Name: assert-pytest-class-holds-state
|
|
3
|
+
Version: 20260907154656
|
|
4
|
+
Summary: CLI tool to assert that every pytest class holds a fixture, an attribute, a helper or a base
|
|
5
|
+
Author-email: 10U Labs <dev@10ulabs.com>
|
|
6
|
+
License-Expression: Apache-2.0
|
|
7
|
+
Project-URL: Homepage, https://github.com/10U-Labs/assert-pytest-class-holds-state
|
|
8
|
+
Project-URL: Repository, https://github.com/10U-Labs/assert-pytest-class-holds-state
|
|
9
|
+
Classifier: Development Status :: 4 - Beta
|
|
10
|
+
Classifier: Environment :: Console
|
|
11
|
+
Classifier: Intended Audience :: Developers
|
|
12
|
+
Classifier: Operating System :: OS Independent
|
|
13
|
+
Classifier: Programming Language :: Python :: 3
|
|
14
|
+
Classifier: Programming Language :: Python :: 3.10
|
|
15
|
+
Classifier: Programming Language :: Python :: 3.11
|
|
16
|
+
Classifier: Programming Language :: Python :: 3.12
|
|
17
|
+
Classifier: Programming Language :: Python :: 3.13
|
|
18
|
+
Classifier: Topic :: Software Development :: Quality Assurance
|
|
19
|
+
Classifier: Topic :: Software Development :: Testing
|
|
20
|
+
Requires-Python: >=3.10
|
|
21
|
+
Description-Content-Type: text/markdown
|
|
22
|
+
License-File: LICENSE.txt
|
|
23
|
+
Dynamic: license-file
|
|
24
|
+
|
|
25
|
+
# assert-pytest-class-holds-state
|
|
26
|
+
|
|
27
|
+
Assert that every pytest class holds a fixture, an attribute, a helper or a
|
|
28
|
+
base.
|
|
29
|
+
|
|
30
|
+
## Why Must a Class Hold Something?
|
|
31
|
+
|
|
32
|
+
A pytest class earns its place three ways. It holds a fixture, whose scope is
|
|
33
|
+
then the class. It holds an attribute or a helper that its methods reach
|
|
34
|
+
through `self`. Or it derives from a shared suite, collecting one set of tests
|
|
35
|
+
for many subjects.
|
|
36
|
+
|
|
37
|
+
A class that does none of those is a namespace. It costs an unused `self` on
|
|
38
|
+
every signature, a level of indentation on every body, a prefix on every node
|
|
39
|
+
ID, and it suggests a setup that is not there. The methods belong at module
|
|
40
|
+
level, where pytest collects them just as readily.
|
|
41
|
+
|
|
42
|
+
`no-self-use` is the mechanical signal and the wrong instrument. It reports on
|
|
43
|
+
a method that happens not to touch `self`, so it flags an `autouse` fixture
|
|
44
|
+
sitting in the class that is its scope, and it flags a kept class's one
|
|
45
|
+
stateless method. This tool asks what the class is for instead, so a class that
|
|
46
|
+
holds anything at all is silent rather than waived.
|
|
47
|
+
|
|
48
|
+
## Installation
|
|
49
|
+
|
|
50
|
+
```bash
|
|
51
|
+
pip install assert-pytest-class-holds-state
|
|
52
|
+
```
|
|
53
|
+
|
|
54
|
+
## Usage
|
|
55
|
+
|
|
56
|
+
### Command Line
|
|
57
|
+
|
|
58
|
+
```bash
|
|
59
|
+
# Scan specific files
|
|
60
|
+
assert-pytest-class-holds-state test_example.py
|
|
61
|
+
|
|
62
|
+
# Scan directories recursively
|
|
63
|
+
assert-pytest-class-holds-state test/
|
|
64
|
+
|
|
65
|
+
# Use glob patterns
|
|
66
|
+
assert-pytest-class-holds-state "test/**/test_*.py"
|
|
67
|
+
|
|
68
|
+
# Exclude patterns
|
|
69
|
+
assert-pytest-class-holds-state test/ --exclude "**/conftest.py"
|
|
70
|
+
|
|
71
|
+
# Verbose output
|
|
72
|
+
assert-pytest-class-holds-state test/ --verbose
|
|
73
|
+
|
|
74
|
+
# Fail fast (exit on first finding)
|
|
75
|
+
assert-pytest-class-holds-state test/ --fail-fast
|
|
76
|
+
|
|
77
|
+
# Warn only (always exit 0)
|
|
78
|
+
assert-pytest-class-holds-state test/ --warn-only
|
|
79
|
+
```
|
|
80
|
+
|
|
81
|
+
### GitHub Actions
|
|
82
|
+
|
|
83
|
+
```yaml
|
|
84
|
+
- uses: 10U-Labs/assert-pytest-class-holds-state@latest
|
|
85
|
+
with:
|
|
86
|
+
files: "test/"
|
|
87
|
+
verbose: "true"
|
|
88
|
+
```
|
|
89
|
+
|
|
90
|
+
### As a Python Module
|
|
91
|
+
|
|
92
|
+
```bash
|
|
93
|
+
python -m assert_pytest_class_holds_state test/
|
|
94
|
+
```
|
|
95
|
+
|
|
96
|
+
## Output Format
|
|
97
|
+
|
|
98
|
+
Default output shows one finding per line:
|
|
99
|
+
|
|
100
|
+
```text
|
|
101
|
+
path/to/test_file.py:10:TestExample: the test methods belong at module level
|
|
102
|
+
```
|
|
103
|
+
|
|
104
|
+
Format: `file_path:line_number:class_name`, followed by the reason. The line
|
|
105
|
+
number is the `class` statement.
|
|
106
|
+
|
|
107
|
+
## Exit Codes
|
|
108
|
+
|
|
109
|
+
- `0`: No findings (or `--warn-only` specified)
|
|
110
|
+
- `1`: Findings detected
|
|
111
|
+
- `2`: Error (missing files, syntax errors, etc.)
|
|
112
|
+
|
|
113
|
+
## What Counts as Holding Something?
|
|
114
|
+
|
|
115
|
+
A class whose name begins with `Test` is refused only when all four of these
|
|
116
|
+
are true:
|
|
117
|
+
|
|
118
|
+
- it has no base and no class keyword
|
|
119
|
+
- it carries no decorator
|
|
120
|
+
- its body holds no assignment
|
|
121
|
+
- every function in its body is a test — a name beginning with `test` that no
|
|
122
|
+
`pytest.fixture` decorator files as a fixture
|
|
123
|
+
|
|
124
|
+
Anything else passes. An inheritance stub passes on its base, even with an
|
|
125
|
+
empty body. A fixture holder passes on the fixture, `autouse` or not. A class
|
|
126
|
+
holding a `@staticmethod` helper, a plain helper, or a `setup_method` passes on
|
|
127
|
+
the non-test function. A class carrying `@pytest.mark.integration` passes on
|
|
128
|
+
the decorator, and one carrying `region = "us-east-2"` passes on the
|
|
129
|
+
assignment.
|
|
130
|
+
|
|
131
|
+
A decorator on a *method* is not a decorator on the class, so
|
|
132
|
+
`@pytest.mark.parametrize` on every test does not save a namespace.
|
|
133
|
+
|
|
134
|
+
## What Is Never Examined
|
|
135
|
+
|
|
136
|
+
A class defined inside a function is a suite the function produces, not a
|
|
137
|
+
namespace someone wrote around loose methods. Its methods close over the
|
|
138
|
+
function's arguments and cannot move to module level, and pytest never collects
|
|
139
|
+
it until another module inherits from it. The tool does not descend into
|
|
140
|
+
function bodies at all.
|
|
141
|
+
|
|
142
|
+
Only files pytest would collect are scanned: `test_*.py` and `*_test.py`.
|
|
143
|
+
|
|
144
|
+
## Options
|
|
145
|
+
|
|
146
|
+
| Option | Description |
|
|
147
|
+
| --------------------- | ------------------------------------------ |
|
|
148
|
+
| `--exclude PATTERNS` | Glob patterns to exclude (comma-separated) |
|
|
149
|
+
| `--quiet` | Suppress all output (exit code only) |
|
|
150
|
+
| `--count` | Output only the number of findings |
|
|
151
|
+
| `--verbose` | Show detailed processing information |
|
|
152
|
+
| `--fail-fast` | Exit after first finding |
|
|
153
|
+
| `--warn-only` | Always exit 0, even with findings |
|
|
154
|
+
|
|
155
|
+
## License
|
|
156
|
+
|
|
157
|
+
Apache 2.0 - See [LICENSE.txt](LICENSE.txt)
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
assert_pytest_class_holds_state/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
|
2
|
+
assert_pytest_class_holds_state/__main__.py,sha256=bYt9eEaoRQWdejEHFD8REx9jxVEdZptECFsV7F49Ink,30
|
|
3
|
+
assert_pytest_class_holds_state/cli.py,sha256=hunrzWfKpNLzRjTZEio7y7rB5ZYyzNg2Fp-e2YnOFY4,7275
|
|
4
|
+
assert_pytest_class_holds_state/py.typed,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
|
5
|
+
assert_pytest_class_holds_state/scanner.py,sha256=vgprhpPPng9gKpsEGJ4bdo_upn2t2O0zDSTd3Ye676o,2441
|
|
6
|
+
assert_pytest_class_holds_state-20260907154656.dist-info/licenses/LICENSE.txt,sha256=7C7FkuzwSQFE_PL6st5x2YyMN1aiyjZ9ti1s5X45no8,10761
|
|
7
|
+
assert_pytest_class_holds_state-20260907154656.dist-info/METADATA,sha256=QaskbnOCtUxw-ldg6QY7TtlH8S9p3vyXdg2GZFnXlRU,5329
|
|
8
|
+
assert_pytest_class_holds_state-20260907154656.dist-info/WHEEL,sha256=YVMoNqKzERt-wjUZwJ33xBGAwnFl-4cqbYkTtWa4itE,91
|
|
9
|
+
assert_pytest_class_holds_state-20260907154656.dist-info/entry_points.txt,sha256=mqxHAbKlWnbjjvD2W-J-Tt_FsPs6ygFOlwba-5QSIh8,93
|
|
10
|
+
assert_pytest_class_holds_state-20260907154656.dist-info/top_level.txt,sha256=Lb-z6qlq6q0iloxbsAxrLjdTbSqO3KREZDPapLRpEg0,32
|
|
11
|
+
assert_pytest_class_holds_state-20260907154656.dist-info/RECORD,,
|
|
@@ -0,0 +1,190 @@
|
|
|
1
|
+
Apache License
|
|
2
|
+
Version 2.0, January 2004
|
|
3
|
+
http://www.apache.org/licenses/
|
|
4
|
+
|
|
5
|
+
TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
|
|
6
|
+
|
|
7
|
+
1. Definitions.
|
|
8
|
+
|
|
9
|
+
"License" shall mean the terms and conditions for use, reproduction,
|
|
10
|
+
and distribution as defined by Sections 1 through 9 of this document.
|
|
11
|
+
|
|
12
|
+
"Licensor" shall mean the copyright owner or entity authorized by
|
|
13
|
+
the copyright owner that is granting the License.
|
|
14
|
+
|
|
15
|
+
"Legal Entity" shall mean the union of the acting entity and all
|
|
16
|
+
other entities that control, are controlled by, or are under common
|
|
17
|
+
control with that entity. For the purposes of this definition,
|
|
18
|
+
"control" means (i) the power, direct or indirect, to cause the
|
|
19
|
+
direction or management of such entity, whether by contract or
|
|
20
|
+
otherwise, or (ii) ownership of fifty percent (50%) or more of the
|
|
21
|
+
outstanding shares, or (iii) beneficial ownership of such entity.
|
|
22
|
+
|
|
23
|
+
"You" (or "Your") shall mean an individual or Legal Entity
|
|
24
|
+
exercising permissions granted by this License.
|
|
25
|
+
|
|
26
|
+
"Source" form shall mean the preferred form for making modifications,
|
|
27
|
+
including but not limited to software source code, documentation
|
|
28
|
+
source, and configuration files.
|
|
29
|
+
|
|
30
|
+
"Object" form shall mean any form resulting from mechanical
|
|
31
|
+
transformation or translation of a Source form, including but
|
|
32
|
+
not limited to compiled object code, generated documentation,
|
|
33
|
+
and conversions to other media types.
|
|
34
|
+
|
|
35
|
+
"Work" shall mean the work of authorship, whether in Source or
|
|
36
|
+
Object form, made available under the License, as indicated by a
|
|
37
|
+
copyright notice that is included in or attached to the work
|
|
38
|
+
(an example is provided in the Appendix below).
|
|
39
|
+
|
|
40
|
+
"Derivative Works" shall mean any work, whether in Source or Object
|
|
41
|
+
form, that is based on (or derived from) the Work and for which the
|
|
42
|
+
editorial revisions, annotations, elaborations, or other modifications
|
|
43
|
+
represent, as a whole, an original work of authorship. For the purposes
|
|
44
|
+
of this License, Derivative Works shall not include works that remain
|
|
45
|
+
separable from, or merely link (or bind by name) to the interfaces of,
|
|
46
|
+
the Work and Derivative Works thereof.
|
|
47
|
+
|
|
48
|
+
"Contribution" shall mean any work of authorship, including
|
|
49
|
+
the original version of the Work and any modifications or additions
|
|
50
|
+
to that Work or Derivative Works thereof, that is intentionally
|
|
51
|
+
submitted to the Licensor for inclusion in the Work by the copyright owner
|
|
52
|
+
or by an individual or Legal Entity authorized to submit on behalf of
|
|
53
|
+
the copyright owner. For the purposes of this definition, "submitted"
|
|
54
|
+
means any form of electronic, verbal, or written communication sent
|
|
55
|
+
to the Licensor or its representatives, including but not limited to
|
|
56
|
+
communication on electronic mailing lists, source code control systems,
|
|
57
|
+
and issue tracking systems that are managed by, or on behalf of, the
|
|
58
|
+
Licensor for the purpose of discussing and improving the Work, but
|
|
59
|
+
excluding communication that is conspicuously marked or otherwise
|
|
60
|
+
designated in writing by the copyright owner as "Not a Contribution."
|
|
61
|
+
|
|
62
|
+
"Contributor" shall mean Licensor and any individual or Legal Entity
|
|
63
|
+
on behalf of whom a Contribution has been received by Licensor and
|
|
64
|
+
subsequently incorporated within the Work.
|
|
65
|
+
|
|
66
|
+
2. Grant of Copyright License. Subject to the terms and conditions of
|
|
67
|
+
this License, each Contributor hereby grants to You a perpetual,
|
|
68
|
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
|
69
|
+
copyright license to reproduce, prepare Derivative Works of,
|
|
70
|
+
publicly display, publicly perform, sublicense, and distribute the
|
|
71
|
+
Work and such Derivative Works in Source or Object form.
|
|
72
|
+
|
|
73
|
+
3. Grant of Patent License. Subject to the terms and conditions of
|
|
74
|
+
this License, each Contributor hereby grants to You a perpetual,
|
|
75
|
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
|
76
|
+
(except as stated in this section) patent license to make, have made,
|
|
77
|
+
use, offer to sell, sell, import, and otherwise transfer the Work,
|
|
78
|
+
where such license applies only to those patent claims licensable
|
|
79
|
+
by such Contributor that are necessarily infringed by their
|
|
80
|
+
Contribution(s) alone or by combination of their Contribution(s)
|
|
81
|
+
with the Work to which such Contribution(s) was submitted. If You
|
|
82
|
+
institute patent litigation against any entity (including a
|
|
83
|
+
cross-claim or counterclaim in a lawsuit) alleging that the Work
|
|
84
|
+
or a Contribution incorporated within the Work constitutes direct
|
|
85
|
+
or contributory patent infringement, then any patent licenses
|
|
86
|
+
granted to You under this License for that Work shall terminate
|
|
87
|
+
as of the date such litigation is filed.
|
|
88
|
+
|
|
89
|
+
4. Redistribution. You may reproduce and distribute copies of the
|
|
90
|
+
Work or Derivative Works thereof in any medium, with or without
|
|
91
|
+
modifications, and in Source or Object form, provided that You
|
|
92
|
+
meet the following conditions:
|
|
93
|
+
|
|
94
|
+
(a) You must give any other recipients of the Work or
|
|
95
|
+
Derivative Works a copy of this License; and
|
|
96
|
+
|
|
97
|
+
(b) You must cause any modified files to carry prominent notices
|
|
98
|
+
stating that You changed the files; and
|
|
99
|
+
|
|
100
|
+
(c) You must retain, in the Source form of any Derivative Works
|
|
101
|
+
that You distribute, all copyright, patent, trademark, and
|
|
102
|
+
attribution notices from the Source form of the Work,
|
|
103
|
+
excluding those notices that do not pertain to any part of
|
|
104
|
+
the Derivative Works; and
|
|
105
|
+
|
|
106
|
+
(d) If the Work includes a "NOTICE" text file as part of its
|
|
107
|
+
distribution, then any Derivative Works that You distribute must
|
|
108
|
+
include a readable copy of the attribution notices contained
|
|
109
|
+
within such NOTICE file, excluding those notices that do not
|
|
110
|
+
pertain to any part of the Derivative Works, in at least one
|
|
111
|
+
of the following places: within a NOTICE text file distributed
|
|
112
|
+
as part of the Derivative Works; within the Source form or
|
|
113
|
+
documentation, if provided along with the Derivative Works; or,
|
|
114
|
+
within a display generated by the Derivative Works, if and
|
|
115
|
+
wherever such third-party notices normally appear. The contents
|
|
116
|
+
of the NOTICE file are for informational purposes only and
|
|
117
|
+
do not modify the License. You may add Your own attribution
|
|
118
|
+
notices within Derivative Works that You distribute, alongside
|
|
119
|
+
or as an addendum to the NOTICE text from the Work, provided
|
|
120
|
+
that such additional attribution notices cannot be construed
|
|
121
|
+
as modifying the License.
|
|
122
|
+
|
|
123
|
+
You may add Your own copyright statement to Your modifications and
|
|
124
|
+
may provide additional or different license terms and conditions
|
|
125
|
+
for use, reproduction, or distribution of Your modifications, or
|
|
126
|
+
for any such Derivative Works as a whole, provided Your use,
|
|
127
|
+
reproduction, and distribution of the Work otherwise complies with
|
|
128
|
+
the conditions stated in this License.
|
|
129
|
+
|
|
130
|
+
5. Submission of Contributions. Unless You explicitly state otherwise,
|
|
131
|
+
any Contribution intentionally submitted for inclusion in the Work
|
|
132
|
+
by You to the Licensor shall be under the terms and conditions of
|
|
133
|
+
this License, without any additional terms or conditions.
|
|
134
|
+
Notwithstanding the above, nothing herein shall supersede or modify
|
|
135
|
+
the terms of any separate license agreement you may have executed
|
|
136
|
+
with Licensor regarding such Contributions.
|
|
137
|
+
|
|
138
|
+
6. Trademarks. This License does not grant permission to use the trade
|
|
139
|
+
names, trademarks, service marks, or product names of the Licensor,
|
|
140
|
+
except as required for reasonable and customary use in describing the
|
|
141
|
+
origin of the Work and reproducing the content of the NOTICE file.
|
|
142
|
+
|
|
143
|
+
7. Disclaimer of Warranty. Unless required by applicable law or
|
|
144
|
+
agreed to in writing, Licensor provides the Work (and each
|
|
145
|
+
Contributor provides its Contributions) on an "AS IS" BASIS,
|
|
146
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
|
|
147
|
+
implied, including, without limitation, any warranties or conditions
|
|
148
|
+
of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
|
|
149
|
+
PARTICULAR PURPOSE. You are solely responsible for determining the
|
|
150
|
+
appropriateness of using or redistributing the Work and assume any
|
|
151
|
+
risks associated with Your exercise of permissions under this License.
|
|
152
|
+
|
|
153
|
+
8. Limitation of Liability. In no event and under no legal theory,
|
|
154
|
+
whether in tort (including negligence), contract, or otherwise,
|
|
155
|
+
unless required by applicable law (such as deliberate and grossly
|
|
156
|
+
negligent acts) or agreed to in writing, shall any Contributor be
|
|
157
|
+
liable to You for damages, including any direct, indirect, special,
|
|
158
|
+
incidental, or consequential damages of any character arising as a
|
|
159
|
+
result of this License or out of the use or inability to use the
|
|
160
|
+
Work (including but not limited to damages for loss of goodwill,
|
|
161
|
+
work stoppage, computer failure or malfunction, or any and all
|
|
162
|
+
other commercial damages or losses), even if such Contributor
|
|
163
|
+
has been advised of the possibility of such damages.
|
|
164
|
+
|
|
165
|
+
9. Accepting Warranty or Additional Liability. While redistributing
|
|
166
|
+
the Work or Derivative Works thereof, You may choose to offer,
|
|
167
|
+
and charge a fee for, acceptance of support, warranty, indemnity,
|
|
168
|
+
or other liability obligations and/or rights consistent with this
|
|
169
|
+
License. However, in accepting such obligations, You may act only
|
|
170
|
+
on Your own behalf and on Your sole responsibility, not on behalf
|
|
171
|
+
of any other Contributor, and only if You agree to indemnify,
|
|
172
|
+
defend, and hold each Contributor harmless for any liability
|
|
173
|
+
incurred by, or claims asserted against, such Contributor by reason
|
|
174
|
+
of your accepting any such warranty or additional liability.
|
|
175
|
+
|
|
176
|
+
END OF TERMS AND CONDITIONS
|
|
177
|
+
|
|
178
|
+
Copyright 2024 10U Labs LLC
|
|
179
|
+
|
|
180
|
+
Licensed under the Apache License, Version 2.0 (the "License");
|
|
181
|
+
you may not use this file except in compliance with the License.
|
|
182
|
+
You may obtain a copy of the License at
|
|
183
|
+
|
|
184
|
+
http://www.apache.org/licenses/LICENSE-2.0
|
|
185
|
+
|
|
186
|
+
Unless required by applicable law or agreed to in writing, software
|
|
187
|
+
distributed under the License is distributed on an "AS IS" BASIS,
|
|
188
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
189
|
+
See the License for the specific language governing permissions and
|
|
190
|
+
limitations under the License.
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
assert_pytest_class_holds_state
|