Skip to content

Commit

Permalink
appease mypy and make output nicer.
Browse files Browse the repository at this point in the history
  • Loading branch information
gpshead committed Nov 28, 2023
1 parent e238589 commit 9754156
Showing 1 changed file with 17 additions and 10 deletions.
27 changes: 17 additions & 10 deletions tests/integration/test_pep517.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
import sys

from pathlib import Path
from typing import TYPE_CHECKING
from typing import Any, Callable, TYPE_CHECKING

import pytest

Expand All @@ -24,22 +24,29 @@
pytestmark = pytest.mark.integration


def verbose_called_process_error(test_function):
def verbose_called_process_error(test_function: Callable[..., None]) -> Callable[..., None]:
"""Decorator to emit verbose CalledProcessError details on stderr."""

@functools.wraps(test_function)
def verbose_called_process_error_wrapper(*args, **kwargs):
def verbose_called_process_error_wrapper(*args: Any, **kwargs: Any) -> None:
try:
return test_function(*args, **kwargs)
except subprocess.CalledProcessError as error:
sys.stdout.write("\n---=============---\n")
sys.stdout.write(
"CalledProcessError details to workaround the test fixture swallowing"
" it:\n"
try:
stdout = error.stdout.decode('utf-8')
except UnicodeError:
stdout = error.stdout
try:
stderr = error.stderr.decode('utf-8')
except UnicodeError:
stderr = error.stderr
sys.stderr.write("\n---=============---\n")
sys.stderr.write(
"CalledProcessError details (test fixtures can swallow it):\n"
)
sys.stdout.write(f"stdout = {error.stdout}\n")
sys.stdout.write(f"stderr = {error.stderr}\n")
sys.stdout.write("---=============---\n")
sys.stderr.write(f"stdout = {stdout}\n")
sys.stderr.write(f"stderr = {stderr}\n")
sys.stderr.write("---=============---\n")
raise

return verbose_called_process_error_wrapper
Expand Down

0 comments on commit 9754156

Please sign in to comment.