summaryrefslogtreecommitdiff
path: root/tests
diff options
context:
space:
mode:
authorAdam Johnson <me@adamj.eu>2025-01-04 03:29:53 +0000
committerGitHub <noreply@github.com>2025-01-04 00:29:53 -0300
commitec0e784f91b551c654f0962431cc31091926792d (patch)
treef317b4bbc20e810a97d61187f998802fe000c100 /tests
parenta4d3f2535ec1f490c26ecf6c24b95105cd888dd9 (diff)
Fixed #36056 -- Made OutputWrapper a virtual subclass of TextIOBase.
This fixes the ignored exception in self._out.flush() from django.core.management.base.OutputWrapper: `ValueError: I/O operation on closed file.`
Diffstat (limited to 'tests')
-rw-r--r--tests/user_commands/tests.py26
1 files changed, 25 insertions, 1 deletions
diff --git a/tests/user_commands/tests.py b/tests/user_commands/tests.py
index 2add272c10..acc338685e 100644
--- a/tests/user_commands/tests.py
+++ b/tests/user_commands/tests.py
@@ -1,7 +1,7 @@
import os
import sys
from argparse import ArgumentDefaultsHelpFormatter
-from io import StringIO
+from io import BytesIO, StringIO, TextIOWrapper
from pathlib import Path
from unittest import mock
@@ -11,6 +11,7 @@ from django.apps import apps
from django.core import management
from django.core.checks import Tags
from django.core.management import BaseCommand, CommandError, find_commands
+from django.core.management.base import OutputWrapper
from django.core.management.utils import (
find_command,
get_random_secret_key,
@@ -28,6 +29,29 @@ from .management.commands import dance
from .utils import AssertFormatterFailureCaughtContext
+class OutputWrapperTests(SimpleTestCase):
+ def test_unhandled_exceptions(self):
+ cases = [
+ StringIO("Hello world"),
+ TextIOWrapper(BytesIO(b"Hello world")),
+ ]
+ for out in cases:
+ with self.subTest(out=out):
+ wrapper = OutputWrapper(out)
+ out.close()
+
+ unraisable_exceptions = []
+
+ def unraisablehook(unraisable):
+ unraisable_exceptions.append(unraisable)
+ sys.__unraisablehook__(unraisable)
+
+ with mock.patch.object(sys, "unraisablehook", unraisablehook):
+ del wrapper
+
+ self.assertEqual(unraisable_exceptions, [])
+
+
# A minimal set of apps to avoid system checks running on all apps.
@override_settings(
INSTALLED_APPS=[