Skip to content

Commit 0856d7d

Browse files
committed
set test bool when using it in tests
Signed-off-by: Zack Koppert <[email protected]>
1 parent 2b4cce2 commit 0856d7d

File tree

2 files changed

+15
-5
lines changed

2 files changed

+15
-5
lines changed

issue_metrics.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -122,12 +122,12 @@ def auth_to_github(
122122

123123
def get_per_issue_metrics(
124124
issues: Union[List[dict], List[github3.search.IssueSearchResult]], # type: ignore
125+
env_vars: EnvVars,
125126
discussions: bool = False,
126127
labels: Union[List[str], None] = None,
127128
ignore_users: Union[List[str], None] = None,
128129
max_comments_to_eval: int = 20,
129130
heavily_involved: int = 3,
130-
env_vars: EnvVars = get_env_vars(),
131131
) -> tuple[List, int, int]:
132132
"""
133133
Calculate the metrics for each issue/pr/discussion in a list provided.

test_issue_metrics.py

Lines changed: 14 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -108,8 +108,8 @@ def test_get_env_vars(self):
108108
"""Test that the function correctly retrieves the environment variables."""
109109

110110
# Call the function and check the result
111-
search_query = get_env_vars().search_query
112-
gh_token = get_env_vars().gh_token
111+
search_query = get_env_vars(test=True).search_query
112+
gh_token = get_env_vars(test=True).gh_token
113113
gh_token_expected_result = "test_token"
114114
search_query_expected_result = "is:issue is:open repo:user/repo"
115115
self.assertEqual(gh_token, gh_token_expected_result)
@@ -238,6 +238,10 @@ def test_main_no_issues_found(
238238
class TestGetPerIssueMetrics(unittest.TestCase):
239239
"""Test suite for the get_per_issue_metrics function."""
240240

241+
@patch.dict(
242+
os.environ,
243+
{"GH_TOKEN": "test_token", "SEARCH_QUERY": "is:issue is:open repo:user/repo"},
244+
)
241245
def test_get_per_issue_metrics(self):
242246
"""Test that the function correctly calculates the metrics for a list of GitHub issues."""
243247
# Create mock data
@@ -286,7 +290,7 @@ def test_get_per_issue_metrics(self):
286290
result_issues_with_metrics,
287291
result_num_issues_open,
288292
result_num_issues_closed,
289-
) = get_per_issue_metrics(issues)
293+
) = get_per_issue_metrics(issues, env_vars=get_env_vars(test=True))
290294
expected_issues_with_metrics = [
291295
IssueWithMetrics(
292296
"Issue 1",
@@ -364,14 +368,20 @@ def setUp(self):
364368
"closedAt": "2023-01-07T00:00:00Z",
365369
}
366370

371+
@patch.dict(
372+
os.environ,
373+
{"GH_TOKEN": "test_token", "SEARCH_QUERY": "is:issue is:open repo:user/repo"},
374+
)
367375
def test_get_per_issue_metrics_with_discussion(self):
368376
"""
369377
Test that the function correctly calculates
370378
the metrics for a list of GitHub issues with discussions.
371379
"""
372380

373381
issues = [self.issue1, self.issue2]
374-
metrics = get_per_issue_metrics(issues, discussions=True)
382+
metrics = get_per_issue_metrics(
383+
issues, discussions=True, env_vars=get_env_vars(test=True)
384+
)
375385

376386
# get_per_issue_metrics returns a tuple of
377387
# (issues_with_metrics, num_issues_open, num_issues_closed)

0 commit comments

Comments
 (0)