Debian Codegraph @

tests/user_commands/utils.py

raw
1 from io import StringIO
2 from unittest import mock
3
4
5 class AssertFormatterFailureCaughtContext:
6
7 def __init__(self, test, shutil_which_result="nonexistent"):
8 self.stdout = StringIO()
9 self.stderr = StringIO()
10 self.test = test
11 self.shutil_which_result = shutil_which_result
12
13 def __enter__(self):
14 self.mocker = mock.patch(
15 "django.core.management.utils.shutil.which",
16 return_value=self.shutil_which_result,
17 )
18 self.mocker.start()
19 return self
20
21 def __exit__(self, exc_type, exc_value, traceback):
22 self.mocker.stop()
23 self.test.assertIn("Formatters failed to launch", self.stderr.getvalue())