diff --git a/beets/test/_common.py b/beets/test/_common.py index 487f7c442..10083c8cb 100644 --- a/beets/test/_common.py +++ b/beets/test/_common.py @@ -190,14 +190,6 @@ class DummyIO: def readcount(self): return self.stdin.reads - def install(self): - sys.stdin = self.stdin - sys.stdout = self.stdout - - def restore(self): - sys.stdin = sys.__stdin__ - sys.stdout = sys.__stdout__ - # Utility. diff --git a/beets/test/helper.py b/beets/test/helper.py index 207b0e491..582d7ac43 100644 --- a/beets/test/helper.py +++ b/beets/test/helper.py @@ -168,13 +168,14 @@ class IOMixin: def io(self) -> _common.DummyIO: return _common.DummyIO() - def setUp(self): + def setUp(self) -> None: super().setUp() - self.io.install() - def tearDown(self): - super().tearDown() - self.io.restore() + patcher = patch.multiple( + "sys", stdin=self.io.stdin, stdout=self.io.stdout + ) + patcher.start() + self.addCleanup(patcher.stop) class TestHelper(ConfigMixin): @@ -759,7 +760,6 @@ class TerminalImportMixin(IOMixin, ImportHelper): io: _common.DummyIO def _get_import_session(self, import_dir: bytes) -> importer.ImportSession: - self.io.install() return TerminalImportSessionFixture( self.lib, loghandler=None, diff --git a/test/ui/commands/test_completion.py b/test/ui/commands/test_completion.py index ee2881a0e..992ed58c8 100644 --- a/test/ui/commands/test_completion.py +++ b/test/ui/commands/test_completion.py @@ -49,7 +49,6 @@ class CompletionTest(IOMixin, TestPluginTestCase): # Load completion script. self.run_command("completion", lib=None) completion_script = self.io.getoutput().encode("utf-8") - self.io.restore() tester.stdin.writelines(completion_script.splitlines(True)) # Load test suite.