Skip to content

Commit 7c036fc

Browse files
committed
fix: address code quality review comments
- Remove unused current_branch variable in detect_pr_from_branch - Add explicit return statements after pytest.skip() in decorators - Add diagnostic logging to empty except clauses - Add type annotations to production test fixtures and decorators
1 parent 15bd499 commit 7c036fc

File tree

2 files changed

+17
-14
lines changed

2 files changed

+17
-14
lines changed

scripts/pr_review.py

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -142,8 +142,8 @@ def detect_pr_from_github_actions() -> PRInfo | None:
142142
url=pr.get("html_url"),
143143
state=pr.get("state"),
144144
)
145-
except Exception:
146-
pass
145+
except Exception as e:
146+
print(f"Warning: Could not read/parse GitHub event file: {e}", file=sys.stderr)
147147

148148
if pr_number:
149149
try:
@@ -195,9 +195,10 @@ def get_pr_info_from_gh_cli(pr_number: int | None = None) -> PRInfo | None:
195195
except (json.JSONDecodeError, KeyError):
196196
pass
197197
except FileNotFoundError:
198+
# gh CLI not available - this is expected in some environments
198199
pass
199-
except Exception:
200-
pass
200+
except Exception as e:
201+
print(f"Warning: Error getting PR info from gh CLI: {e}", file=sys.stderr)
201202

202203
return None
203204

@@ -214,11 +215,10 @@ def detect_pr_from_branch() -> PRInfo | None:
214215
check=False,
215216
)
216217
if result.returncode == 0:
217-
current_branch = result.stdout.strip()
218218
# Try to get PR info for this branch
219219
return get_pr_info_from_gh_cli(None)
220-
except Exception:
221-
pass
220+
except Exception as e:
221+
print(f"Warning: Error detecting PR from branch: {e}", file=sys.stderr)
222222

223223
return None
224224

tests/production/conftest.py

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,14 @@
11
"""Pytest configuration and fixtures for production smoke tests"""
22

33
import os
4+
from collections.abc import Callable
45
from functools import wraps
6+
from typing import Any
57

68
import pytest
79
from dotenv import load_dotenv
810

11+
from tango import TangoClient
912
from tango.exceptions import TangoAuthError, TangoRateLimitError
1013

1114
# Load environment variables from .env file if it exists
@@ -16,21 +19,19 @@
1619

1720

1821
@pytest.fixture
19-
def production_client():
22+
def production_client() -> TangoClient:
2023
"""
2124
Create TangoClient for production smoke tests
2225
2326
Requires TANGO_API_KEY environment variable to be set.
2427
"""
25-
from tango import TangoClient
26-
2728
if not API_KEY:
2829
pytest.skip("TANGO_API_KEY environment variable required for production tests")
2930

3031
return TangoClient(api_key=API_KEY)
3132

3233

33-
def handle_auth_error(func):
34+
def handle_auth_error(func: Callable[..., Any]) -> Callable[..., Any]:
3435
"""Decorator to handle authentication errors in production tests
3536
3637
Skips the test if authentication fails, which allows the test suite
@@ -44,16 +45,17 @@ def test_something(production_client):
4445
"""
4546

4647
@wraps(func)
47-
def wrapper(*args, **kwargs):
48+
def wrapper(*args: Any, **kwargs: Any) -> Any:
4849
try:
4950
return func(*args, **kwargs)
5051
except TangoAuthError as e:
5152
pytest.skip(f"Authentication failed: {e}")
53+
return # type: ignore[unreachable] # Explicit return for static analysis
5254

5355
return wrapper
5456

5557

56-
def handle_rate_limit(func):
58+
def handle_rate_limit(func: Callable[..., Any]) -> Callable[..., Any]:
5759
"""Decorator to handle rate limit errors in production tests
5860
5961
Skips the test if rate limit is exceeded, which allows the test suite
@@ -67,10 +69,11 @@ def test_something(production_client):
6769
"""
6870

6971
@wraps(func)
70-
def wrapper(*args, **kwargs):
72+
def wrapper(*args: Any, **kwargs: Any) -> Any:
7173
try:
7274
return func(*args, **kwargs)
7375
except TangoRateLimitError as e:
7476
pytest.skip(f"Rate limit exceeded: {e}")
77+
return # type: ignore[unreachable] # Explicit return for static analysis
7578

7679
return wrapper

0 commit comments

Comments
 (0)