Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit4f594cd

Browse files
authored
Set protocol.file.allow only in tests that need it
Instead of setting environment variables just on CI and for thethe entire pytest command, this has the two test cases that needprotocol.file.allow to be set to "always" (instead of "user") setthem, via a shared fixture, just while those tests are running.Both on CI and for local test runs, this makes it no longernecessary to set this in a global configuration or throughenvironment variables, reducing the setup needed to run the tests.
1 parent92d9ae2 commit4f594cd

File tree

3 files changed

+21
-9
lines changed

3 files changed

+21
-9
lines changed

‎.github/workflows/cygwin-test.yml

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -46,8 +46,4 @@ jobs:
4646
shell:bash.exe -eo pipefail -o igncr "{0}"
4747
run:|
4848
/usr/bin/python -m pytest
49-
env:
50-
GIT_CONFIG_COUNT:"1"
51-
GIT_CONFIG_KEY_0:protocol.file.allow
52-
GIT_CONFIG_VALUE_0:always
5349
continue-on-error:false

‎.github/workflows/pythonpackage.yml

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -56,10 +56,6 @@ jobs:
5656
run:|
5757
set -x
5858
pytest
59-
env:
60-
GIT_CONFIG_COUNT:"1"
61-
GIT_CONFIG_KEY_0:protocol.file.allow
62-
GIT_CONFIG_VALUE_0:always
6359
continue-on-error:false
6460

6561
-name:Documentation

‎test/test_submodule.py

Lines changed: 21 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,13 @@
11
# -*- coding: utf-8 -*-
22
# This module is part of GitPython and is released under
33
# the BSD License: http://www.opensource.org/licenses/bsd-license.php
4+
importcontextlib
45
importos
56
importshutil
67
importtempfile
78
frompathlibimportPath
89
importsys
9-
fromunittestimportskipIf
10+
fromunittestimportmock,skipIf
1011

1112
importpytest
1213

@@ -31,6 +32,23 @@
3132
importos.pathasosp
3233

3334

35+
@contextlib.contextmanager
36+
def_allow_file_protocol():
37+
"""Temporarily set protocol.file.allow to always, using environment variables."""
38+
pair_index=int(os.getenv("GIT_CONFIG_COUNT","0"))
39+
40+
# This is recomputed each time the context is entered, for compatibility with
41+
# existing GIT_CONFIG_* environment variables, even if changed in this process.
42+
patcher=mock.patch.dict(os.environ, {
43+
"GIT_CONFIG_COUNT":str(pair_index+1),
44+
f"GIT_CONFIG_KEY_{pair_index}":"protocol.file.allow",
45+
f"GIT_CONFIG_VALUE_{pair_index}":"always",
46+
})
47+
48+
withpatcher:
49+
yield
50+
51+
3452
classTestRootProgress(RootUpdateProgress):
3553
"""Just prints messages, for now without checking the correctness of the states"""
3654

@@ -709,6 +727,7 @@ def test_add_empty_repo(self, rwdir):
709727
# end for each checkout mode
710728

711729
@with_rw_directory
730+
@_allow_file_protocol()
712731
deftest_list_only_valid_submodules(self,rwdir):
713732
repo_path=osp.join(rwdir,"parent")
714733
repo=git.Repo.init(repo_path)
@@ -737,6 +756,7 @@ def test_list_only_valid_submodules(self, rwdir):
737756
""",
738757
)
739758
@with_rw_directory
759+
@_allow_file_protocol()
740760
deftest_git_submodules_and_add_sm_with_new_commit(self,rwdir):
741761
parent=git.Repo.init(osp.join(rwdir,"parent"))
742762
parent.git.submodule("add",self._small_repo_url(),"module")

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp