pytest-api-cov 0.1.0__tar.gz → 0.1.1__tar.gz

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.
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: pytest-api-cov
3
- Version: 0.1.0
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,6 +1,6 @@
1
1
  [project]
2
2
  name = "pytest-api-cov"
3
- version = "0.1.0"
3
+ version = "0.1.1"
4
4
  description = "Api Coverage Report Pytest Plugin"
5
5
  readme = "README.md"
6
6
  authors = [
@@ -17,12 +17,12 @@ dependencies = [
17
17
  "rich>=14.0.0",
18
18
  "starlette>=0.47.1",
19
19
  "tomli>=2.2.1",
20
+ "pytest>=8.4.1",
20
21
  ]
21
22
 
22
23
  [dependency-groups]
23
24
  dev = [
24
25
  "mypy>=1.17.0",
25
- "pytest>=8.4.1",
26
26
  "pytest-cov>=6.2.1",
27
27
  "pytest-sugar>=1.0.0",
28
28
  "pytest-xdist>=3.8.0",
@@ -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
- common_patterns = [
15
- ("app.py", ["app", "application", "main"]),
16
- ("main.py", ["app", "application", "main"]),
17
- ("server.py", ["app", "application", "server"]),
18
- ("wsgi.py", ["app", "application"]),
19
- ("asgi.py", ["app", "application"]),
20
- ]
21
-
22
- for filename, attr_names in common_patterns:
23
- if os.path.exists(filename):
24
- try:
25
- with open(filename, "r") as f:
26
- content = f.read()
27
-
28
- if "from fastapi import" in content or "import fastapi" in content:
29
- framework = "FastAPI"
30
- elif "from flask import" in content or "import flask" in content:
31
- framework = "Flask"
32
- else:
33
- continue
34
-
35
- for attr_name in attr_names:
36
- if f"{attr_name} = " in content:
37
- return framework, filename, attr_name
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
- module_name = file_path[:-3] # Remove .py
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 {module_name} import {app_variable}
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("• main.py")
157
- print("• server.py")
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("""
File without changes
File without changes