Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Attempt to fix flaky GPG test by stopping gpg-agent #104

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 17 additions & 2 deletions tests/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,12 @@
import pytest
import shlex
import os
import py.path
import sys
import tempfile
import textwrap
import subprocess
import traceback
from pathlib import Path
from gitrevise.odb import Repository
from contextlib import contextmanager
from threading import Thread, Event
Expand Down Expand Up @@ -64,7 +64,22 @@ def repo(hermetic_seal):
@pytest.fixture
def short_tmpdir():
with tempfile.TemporaryDirectory() as tdir:
yield py.path.local(tdir)
yield Path(tdir)


@pytest.fixture
def gpg(short_tmpdir, monkeypatch):
# On MacOS, pytest's temp paths are too long for gpg-agent.
# See https://github.com/pytest-dev/pytest/issues/5802
gnupghome = short_tmpdir
monkeypatch.setenv("GNUPGHOME", str(gnupghome))
gnupghome.chmod(0o700)
(gnupghome / "gpg.conf").write_text("pinentry-mode loopback")

try:
yield
finally:
bash("gpgconf --kill all")


@contextmanager
Expand Down
8 changes: 1 addition & 7 deletions tests/test_gpgsign.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,16 +4,10 @@
from subprocess import CalledProcessError, run


def test_gpgsign(repo, short_tmpdir, monkeypatch):
def test_gpgsign(repo, gpg, monkeypatch):
bash("git commit --allow-empty -m 'commit 1'")
assert repo.get_commit("HEAD").gpgsig is None

# On MacOS, pytest's temp paths are too long for gpg-agent.
# See https://github.com/pytest-dev/pytest/issues/5802
gnupghome = short_tmpdir
monkeypatch.setenv("GNUPGHOME", str(gnupghome))
gnupghome.chmod(0o700)
(gnupghome / "gpg.conf").write("pinentry-mode loopback")
user_ident = repo.default_author.signing_key
run(
["gpg", "--batch", "--passphrase", "", "--quick-gen-key", user_ident],
Expand Down