[PATCH b4 05/12] Fix tests under uv with complex git config
Tamir Duberstein <[email protected]>
| Newsgroups | org.kernel.linux.tools |
|---|---|
| Message-ID | <[email protected]> |
Add pytest-asyncio to the dev group so pytest can run async TUI tests. Pin git-filter-repo to unreleased commit 4697eeb for the multiline git config parser fix requested in https://github.com/newren/git-filter-repo/issues/638. That parser fix is the only functional change since v2.47.0: https://github.com/newren/git-filter-repo/compare/v2.47.0...4697eeb37b7c3c30b0492e344f6b89f7139cef26 Inject commit.gpgsign=false through the test fixture so synthetic git commits do not hang on local GPG/pinentry configuration. Also disable attestation through MAIN_CONFIG so tests keep the old can_patatt=false behavior after patatt becomes an unconditional dependency. As a drive-by, route the test b4 globals, pytest sentinel, and XDG env overrides through monkeypatch so each test gets automatic cleanup. Signed-off-by: Tamir Duberstein <[email protected]> --- pyproject.toml | 4 +++- src/tests/conftest.py | 39 +++++++++++++++++++++++++++++---------- 2 files changed, 32 insertions(+), 11 deletions(-) diff --git a/pyproject.toml b/pyproject.toml index 4fad7da..8428c5b 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -24,7 +24,9 @@ classifiers = [ ] dependencies = [ "requests>=2.24,<3.0", - "git-filter-repo>=2.30,<3.0", + # Use unreleased fix for multiline git config values. + # https://github.com/newren/git-filter-repo/issues/638 + "git-filter-repo @ git+https://github.com/newren/git-filter-repo.git@4697eeb37b7c3c30b0492e344f6b89f7139cef26", "dkimpy>=1.0,<2.0", "patatt>=0.6,<2.0", "ezgb>=0.1", diff --git a/src/tests/conftest.py b/src/tests/conftest.py index 3ff3891..83b467d 100644 --- a/src/tests/conftest.py +++ b/src/tests/conftest.py @@ -1,3 +1,4 @@ +import copy import os import pathlib import sys @@ -9,20 +10,38 @@ import b4 @pytest.fixture(scope="function", autouse=True) -def settestdefaults(tmp_path: pathlib.Path) -> None: +def settestdefaults( + monkeypatch: pytest.MonkeyPatch, + tmp_path: pathlib.Path, +) -> None: topdir = b4.git_get_toplevel() if topdir and topdir != os.getcwd(): os.chdir(topdir) - b4.can_network = False - b4.MAIN_CONFIG = dict(b4.DEFAULT_CONFIG) - b4.USER_CONFIG = { - 'name': 'Test Override', - 'email': '[email protected]', - } - os.environ['XDG_DATA_HOME'] = str(tmp_path) - os.environ['XDG_CACHE_HOME'] = str(tmp_path) + monkeypatch.setattr(b4, 'can_network', False) + monkeypatch.setattr( + b4, + 'MAIN_CONFIG', + { + **copy.deepcopy(b4.DEFAULT_CONFIG), + 'attestation-policy': 'off', + }, + ) + monkeypatch.setattr( + b4, + 'USER_CONFIG', + { + 'name': 'Test Override', + 'email': '[email protected]', + }, + ) + monkeypatch.setenv('XDG_DATA_HOME', str(tmp_path)) + monkeypatch.setenv('XDG_CACHE_HOME', str(tmp_path)) + git_config_count = int(os.environ.get('GIT_CONFIG_COUNT', '0')) + monkeypatch.setenv('GIT_CONFIG_COUNT', str(git_config_count + 1)) + monkeypatch.setenv(f'GIT_CONFIG_KEY_{git_config_count}', 'commit.gpgsign') + monkeypatch.setenv(f'GIT_CONFIG_VALUE_{git_config_count}', 'false') # This lets us avoid execvp-ing from inside b4 when testing - sys._running_in_pytest = True # type: ignore[attr-defined] + monkeypatch.setattr(sys, '_running_in_pytest', True, raising=False) @pytest.fixture(scope="function") -- 2.53.0