Skip to content

Commit

Permalink
Leverage pytest-subprocess be more lenient about how the subprocess i…
Browse files Browse the repository at this point in the history
…s invoked.
  • Loading branch information
jaraco committed Apr 23, 2024
1 parent 325a8d2 commit 6faaaa3
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 12 deletions.
1 change: 1 addition & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ testing = [

# local
"path",
"pytest-subprocess",
]
docs = [
# upstream
Expand Down
17 changes: 5 additions & 12 deletions test_all.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import locale
import subprocess
import textwrap

import pytest
Expand Down Expand Up @@ -75,17 +74,11 @@ def scm_defn():


@pytest.fixture()
def fake_git(monkeypatch):
def _fake_sub(cmd, *args, **kwargs):
if cmd[0] != 'git':
raise subprocess.CalledProcessError()
version = cmd[-1]
return {
"1.0": '2015-02-24 22:41:28 -0600',
"1.3": '2016-02-12 11:05:47 -0500',
}[version].encode()

monkeypatch.setattr(subprocess, 'check_output', _fake_sub)
def fake_git(fp):
fp.register(['git', 'status'])
fp.register(['git', 'version'], stdout='git version 2.44.0')
fp.register(['git', 'log', fp.any(), '1.0'], stdout='2015-02-24 22:41:28 -0600')
fp.register(['git', 'log', fp.any(), '1.3'], stdout='2016-02-12 11:05:47 -0500')


def test_scm_example(scm_defn, fake_git):
Expand Down

0 comments on commit 6faaaa3

Please sign in to comment.