Skip to content

test: Use t.Context() instead of context.Background() - #3750

Merged
gmlewis merged 1 commit into
google:masterfrom
alexandear-org:refactor/use-testing-context
Oct 3, 2025
Merged

test: Use t.Context() instead of context.Background()#3750
gmlewis merged 1 commit into
google:masterfrom
alexandear-org:refactor/use-testing-context

Conversation

@alexandear

Copy link
Copy Markdown
Contributor

This PR replaces context.Background() with t.Context() in tests. T.Context has been available since Go 1.24.

Additionally, it enables the usetesting linter to automatically suggest using t.Context() in future PRs.

The PR also modifies the helper function createRandomTestRepository by adding a *testing.T parameter. This simplifies integration tests that rely on this function.

@alexandear
alexandearforce-pushed the refactor/use-testing-context branch from 7684f11 to 7f1bc65CompareOctober 2, 2025 16:02
@alexandear
alexandearforce-pushed the refactor/use-testing-context branch from 7f1bc65 to 64801d6CompareOctober 2, 2025 16:05
@codecov

codecovBot commented Oct 2, 2025

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 91.11%. Comparing base (b7f068f) to head (64801d6).
⚠️ Report is 1 commits behind head on master.

Additional details and impacted files
@@ Coverage Diff @@## master #3750 +/- ##
=======================================
Coverage 91.11% 91.11% =======================================
Files 187 187 Lines 16702 16702 =======================================
Hits 15218 15218 Misses 1296 1296 Partials 188 188 

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@gmlewisgmlewis left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you, @alexandear!
LGTM.
Awaiting second LGTM+Approval from any other contributor to this repo before merging.

cc: @stevehipwell

@gmlewisgmlewis added NeedsReview PR is awaiting a review before merging. and removed NeedsReview PR is awaiting a review before merging. labels Oct 2, 2025
@gmlewis

Copy link
Copy Markdown
Collaborator

Thank you, @zyfy29!
Merging.

@gmlewis
gmlewis merged commit 233fe03 into google:masterOct 3, 2025
7 checks passed
@alexandear
alexandear deleted the refactor/use-testing-context branch October 3, 2025 14:15
jlaportebot added a commit to jlaportebot/go-github that referenced this pull request Jun 28, 2026
Sign up for freeto join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants

@alexandear@gmlewis