Skip to content

Commit

Permalink
test: show output if subprocess fails
Browse files Browse the repository at this point in the history
  • Loading branch information
akaihola committed Aug 8, 2024
1 parent 01f2911 commit 3e82928
Showing 1 changed file with 15 additions and 7 deletions.
22 changes: 15 additions & 7 deletions src/darker/tests/test_main.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
from argparse import ArgumentError
from io import BytesIO
from pathlib import Path
from subprocess import PIPE, run # nosec
from subprocess import PIPE, CalledProcessError, run # nosec
from textwrap import dedent
from types import SimpleNamespace
from unittest.mock import ANY, Mock, call, patch
Expand All @@ -23,6 +23,7 @@
from darker.config import Exclusions
from darker.exceptions import MissingPackageError
from darker.git import EditedLinenumsDiffer
from darker.terminal import output
from darker.tests.helpers import isort_present
from darker.tests.test_fstring import FLYNTED_SOURCE, MODIFIED_SOURCE, ORIGINAL_SOURCE
from darker.verification import NotEquivalentError
Expand Down Expand Up @@ -969,14 +970,21 @@ def test_stdout_newlines_subprocess(newline):
"""
code = f"import collections{newline}import sys{newline}".encode()
try:

darker_subprocess = run( # nosec
["darker", "--stdout", "--isort", "--stdin-filename=new-file.py", "-"],
input=code,
stdout=PIPE,
check=True,
)
darker_subprocess = run( # nosec
["darker", "--stdout", "--isort", "--stdin-filename=new-file.py", "-"],
input=code,
stdout=PIPE,
check=True,
)

except CalledProcessError as e:
if e.stdout:
output(e.stdout, end="\n")
if e.stderr:
output(e.stderr, end="\n")
raise
assert darker_subprocess.stdout == code


Expand Down

0 comments on commit 3e82928

Please sign in to comment.