pytest-api-cov 0.1.0__py3-none-any.whl → 0.1.1__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.
- pytest_api_cov/cli.py +37 -31
- {pytest_api_cov-0.1.0.dist-info → pytest_api_cov-0.1.1.dist-info}/METADATA +2 -1
- {pytest_api_cov-0.1.0.dist-info → pytest_api_cov-0.1.1.dist-info}/RECORD +6 -6
- {pytest_api_cov-0.1.0.dist-info → pytest_api_cov-0.1.1.dist-info}/WHEEL +0 -0
- {pytest_api_cov-0.1.0.dist-info → pytest_api_cov-0.1.1.dist-info}/entry_points.txt +0 -0
- {pytest_api_cov-0.1.0.dist-info → pytest_api_cov-0.1.1.dist-info}/licenses/LICENSE +0 -0
pytest_api_cov/cli.py
CHANGED
@@ -11,47 +11,53 @@ def detect_framework_and_app() -> Optional[tuple[str, str, str]]:
|
|
11
11
|
Detect framework and app location.
|
12
12
|
Returns (framework, file_path, app_variable) or None.
|
13
13
|
"""
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
for
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
except Exception:
|
14
|
+
import glob
|
15
|
+
|
16
|
+
# Search for app files at any depth in current directory
|
17
|
+
app_patterns = ["app.py", "main.py", "server.py", "wsgi.py", "asgi.py"]
|
18
|
+
common_vars = ["app", "application", "main", "server"]
|
19
|
+
|
20
|
+
# Find all matching files recursively
|
21
|
+
found_files = []
|
22
|
+
for pattern in app_patterns:
|
23
|
+
found_files.extend(glob.glob(f"**/{pattern}", recursive=True))
|
24
|
+
|
25
|
+
# Sort by depth (shallowest first) and then by filename priority
|
26
|
+
found_files.sort(key=lambda x: (x.count(os.sep), app_patterns.index(os.path.basename(x))))
|
27
|
+
|
28
|
+
for file_path in found_files:
|
29
|
+
try:
|
30
|
+
with open(file_path, "r") as f:
|
31
|
+
content = f.read()
|
32
|
+
|
33
|
+
if "from fastapi import" in content or "import fastapi" in content:
|
34
|
+
framework = "FastAPI"
|
35
|
+
elif "from flask import" in content or "import flask" in content:
|
36
|
+
framework = "Flask"
|
37
|
+
else:
|
40
38
|
continue
|
41
39
|
|
40
|
+
for var_name in common_vars:
|
41
|
+
if f"{var_name} = " in content:
|
42
|
+
return framework, file_path, var_name
|
43
|
+
|
44
|
+
except Exception:
|
45
|
+
continue
|
46
|
+
|
42
47
|
return None
|
43
48
|
|
44
49
|
|
45
50
|
def generate_conftest_content(framework: str, file_path: str, app_variable: str) -> str:
|
46
51
|
"""Generate conftest.py content based on detected framework."""
|
47
|
-
|
52
|
+
# Convert file path to import path (e.g., "src/main.py" -> "src.main")
|
53
|
+
module_path = file_path.replace("/", ".").replace("\\", ".").replace(".py", "")
|
48
54
|
|
49
55
|
return f'''"""conftest.py - Auto-generated by pytest-api-cov init"""
|
50
56
|
|
51
57
|
import pytest
|
52
58
|
|
53
59
|
# Import your {framework} app
|
54
|
-
from {
|
60
|
+
from {module_path} import {app_variable}
|
55
61
|
|
56
62
|
|
57
63
|
@pytest.fixture
|
@@ -152,9 +158,9 @@ def test_root_endpoint(client):
|
|
152
158
|
print("❌ No FastAPI or Flask app detected in common locations")
|
153
159
|
print()
|
154
160
|
print("Please ensure you have one of these files with a Flask/FastAPI app:")
|
155
|
-
print("• app.py")
|
156
|
-
print("•
|
157
|
-
print("• server
|
161
|
+
print("• app.py, main.py, server.py, wsgi.py, or asgi.py")
|
162
|
+
print("• Files can be in the current directory or any subdirectory")
|
163
|
+
print("• The file must contain a variable named 'app', 'application', 'main', or 'server'")
|
158
164
|
print()
|
159
165
|
print("Example app.py:")
|
160
166
|
print("""
|
@@ -1,6 +1,6 @@
|
|
1
1
|
Metadata-Version: 2.4
|
2
2
|
Name: pytest-api-cov
|
3
|
-
Version: 0.1.
|
3
|
+
Version: 0.1.1
|
4
4
|
Summary: Api Coverage Report Pytest Plugin
|
5
5
|
Author-email: Barnaby Gill <barnabasgill@gmail.com>
|
6
6
|
License: Apache-2.0
|
@@ -10,6 +10,7 @@ Requires-Dist: fastapi>=0.116.1
|
|
10
10
|
Requires-Dist: flask>=3.1.1
|
11
11
|
Requires-Dist: httpx>=0.28.1
|
12
12
|
Requires-Dist: pydantic>=2.11.7
|
13
|
+
Requires-Dist: pytest>=8.4.1
|
13
14
|
Requires-Dist: rich>=14.0.0
|
14
15
|
Requires-Dist: starlette>=0.47.1
|
15
16
|
Requires-Dist: tomli>=2.2.1
|
@@ -1,13 +1,13 @@
|
|
1
1
|
pytest_api_cov/__init__.py,sha256=J7hqjMaNcnMdBP0OB012hPK7ZjhRVDIyd9NBr8gewsc,65
|
2
|
-
pytest_api_cov/cli.py,sha256=
|
2
|
+
pytest_api_cov/cli.py,sha256=ybTMUb8ZzTEcz7g-81kH6Aa7bt4fMNH33ao4laiJ9fY,6211
|
3
3
|
pytest_api_cov/config.py,sha256=cB8N9bpkGmYhXLW3QL08atJy3ukC1vJcSD2qc8tRol0,3166
|
4
4
|
pytest_api_cov/frameworks.py,sha256=5d6wnEsb2BykPtpnpkv98GMPuyoG4elXRJ7vtGHF06A,3228
|
5
5
|
pytest_api_cov/models.py,sha256=YiXLiEEyNREiodzn1pGqSNIHrm3zV6kFn0XgyN8_8Rs,4893
|
6
6
|
pytest_api_cov/plugin.py,sha256=Sa4tWSXmwcXDmxRSAwlM6n4RjU-HqY3S9G8Esicy2nw,11078
|
7
7
|
pytest_api_cov/pytest_flags.py,sha256=aH-MpUQCX7JdPA7f_Qulf0HzOtFpyTqDbHFDy48epOg,1949
|
8
8
|
pytest_api_cov/report.py,sha256=VxfWag20V8o9ArbxOkR_gWQ2TE-sthrS0PCJvn4YCSU,6642
|
9
|
-
pytest_api_cov-0.1.
|
10
|
-
pytest_api_cov-0.1.
|
11
|
-
pytest_api_cov-0.1.
|
12
|
-
pytest_api_cov-0.1.
|
13
|
-
pytest_api_cov-0.1.
|
9
|
+
pytest_api_cov-0.1.1.dist-info/METADATA,sha256=ZDMrv8bDlDRuZYA7pYfzpLe-xYJ3a3y6DZjseU2E6HU,7528
|
10
|
+
pytest_api_cov-0.1.1.dist-info/WHEEL,sha256=qtCwoSJWgHk21S1Kb4ihdzI2rlJ1ZKaIurTj_ngOhyQ,87
|
11
|
+
pytest_api_cov-0.1.1.dist-info/entry_points.txt,sha256=hWqEhsBKzbwSwcxCzKgSA8NElQxk0K4PKERrYsi3csk,110
|
12
|
+
pytest_api_cov-0.1.1.dist-info/licenses/LICENSE,sha256=HrhfyXIkWY2tGFK11kg7vPCqhgh5DcxleloqdhrpyMY,11558
|
13
|
+
pytest_api_cov-0.1.1.dist-info/RECORD,,
|
File without changes
|
File without changes
|
File without changes
|