Skip to content

Commit

Permalink
Fix patching of io.TextWrapper in tests
Browse files Browse the repository at this point in the history
`patch("io.TextIOWrapper")` wouldn't actually cause
`io.TextIOWrrapper()` to return the `StringIO` object created by the
test. This stated to fail as soon as `content=` is non-empty.
  • Loading branch information
Antti Kaihola committed Sep 9, 2021
1 parent 41e6700 commit 0f837d3
Showing 1 changed file with 4 additions and 2 deletions.
6 changes: 4 additions & 2 deletions tests/test_black.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@
)
import pytest
import unittest
from unittest.mock import patch, MagicMock
from unittest.mock import patch, MagicMock, Mock
from parameterized import parameterized

import click
Expand Down Expand Up @@ -1689,7 +1689,9 @@ def test_reformat_one_with_stdin_and_existing_path(self) -> None:

def test_reformat_one_with_stdin_empty(self) -> None:
output = io.StringIO()
with patch("io.TextIOWrapper", lambda *args, **kwargs: output):
mock_io = Mock()
mock_io.TextIOWrapper.return_value = output
with patch.object(black, "io", mock_io):
try:
black.format_stdin_to_stdout(
fast=True,
Expand Down

0 comments on commit 0f837d3

Please sign in to comment.