From 7d93098fd0f305f842940d94963c2b9aa6186505 Mon Sep 17 00:00:00 2001 From: Florian Bruhin Date: Thu, 15 Apr 2021 10:54:17 +0200 Subject: tests: Fix test_version with git's init.defaultBranch (cherry picked from commit 32604a6651813e25ee6d328c880ef95f76c9c744) --- tests/unit/utils/test_version.py | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/tests/unit/utils/test_version.py b/tests/unit/utils/test_version.py index 59f9052ca..b50352e34 100644 --- a/tests/unit/utils/test_version.py +++ b/tests/unit/utils/test_version.py @@ -484,8 +484,17 @@ class TestGitStrSubprocess: @needs_git def test_real_git(self, git_repo): """Test with a real git repository.""" + branch_name = subprocess.run( + ['git', 'config', 'init.defaultBranch'], + check=False, + stdout=subprocess.PIPE, + encoding='utf-8', + ).stdout.strip() + if not branch_name: + branch_name = 'master' + ret = version._git_str_subprocess(str(git_repo)) - assert ret == '6e4b65a on master (1970-01-01 01:00:00 +0100)' + assert ret == f'6e4b65a on {branch_name} (1970-01-01 01:00:00 +0100)' def test_missing_dir(self, tmp_path): """Test with a directory which doesn't exist.""" -- cgit v1.2.3-54-g00ecf