Isolating test from accessing global git credential helper config (#16895)

## Summary
Resolves: https://github.com/astral-sh/uv/issues/1980

Added a utility function to TestContext called
**with_git_credential_helper_blocked** that isolates the test from
accessing the credential helper value defined in global/system git
config. It does so, by writing to a file .gitconfig in the temporary
home_dir that is created as part of the TestContext.

## Test Plan
Tested it by running the test
pip_install::install_git_private_https_pat_and_username, and making sure
it doesn't affect the keyring.

## Note:
The commit hash for the uv-private-package seems to have changed.
Kindly, ensure that the modification related to that is correct.
This commit is contained in:
Sidharth Anil
2025-12-01 06:41:21 -05:00
committed by GitHub
parent 825ab78790
commit 5773b12fa9
2 changed files with 19 additions and 7 deletions
+17 -1
View File
@@ -12,10 +12,13 @@ use uv_python::downloads::ManagedPythonDownloadList;
use assert_cmd::assert::{Assert, OutputAssertExt};
use assert_fs::assert::PathAssert;
use assert_fs::fixture::{ChildPath, PathChild, PathCopy, PathCreateDir, SymlinkToFile};
use assert_fs::fixture::{
ChildPath, FileWriteStr, PathChild, PathCopy, PathCreateDir, SymlinkToFile,
};
use base64::{Engine, prelude::BASE64_STANDARD as base64};
use futures::StreamExt;
use indoc::formatdoc;
use indoc::indoc;
use itertools::Itertools;
use predicates::prelude::predicate;
use regex::Regex;
@@ -563,6 +566,19 @@ impl TestContext {
self
}
// Unsets the git credential helper using temp home gitconfig
pub fn with_unset_git_credential_helper(self) -> Self {
let git_config = self.home_dir.child(".gitconfig");
git_config
.write_str(indoc! {r"
[credential]
helper =
"})
.expect("Failed to unset git credential helper");
self
}
/// Clear filters on `TestContext`.
pub fn clear_filters(mut self) -> Self {
self.filters.clear();
+2 -6
View File
@@ -2501,14 +2501,10 @@ fn install_git_private_https_pat_at_ref() {
/// Install a package from a private GitHub repository using a PAT and username
/// An arbitrary username is supported when using a PAT.
///
/// TODO(charlie): This test modifies the user's keyring.
/// See: <https://github.com/astral-sh/uv/issues/1980>.
#[test]
#[cfg(feature = "git")]
#[ignore = "Modifies the user's keyring"]
fn install_git_private_https_pat_and_username() {
let context = TestContext::new(DEFAULT_PYTHON_VERSION);
let context = TestContext::new(DEFAULT_PYTHON_VERSION).with_unset_git_credential_helper();
let token = decode_token(common::READ_ONLY_GITHUB_TOKEN);
let user = "astral-test-bot";
@@ -2522,7 +2518,7 @@ fn install_git_private_https_pat_and_username() {
Resolved 1 package in [TIME]
Prepared 1 package in [TIME]
Installed 1 package in [TIME]
+ uv-private-pypackage==0.1.0 (from git+https://astral-test-bot:****@github.com/astral-test/uv-private-pypackage@6c09ce9ae81f50670a60abd7d95f30dd416d00ac)
+ uv-private-pypackage==0.1.0 (from git+https://astral-test-bot:****@github.com/astral-test/uv-private-pypackage@d780faf0ac91257d4d5a4f0c5a0e4509608c0071)
"###);
context.assert_installed("uv_private_pypackage", "0.1.0");