From b69e5e7ef69d5b831abe2f1fd3d5413a8f18bd60 Mon Sep 17 00:00:00 2001 From: Adrian Sampson Date: Fri, 15 Dec 2023 09:28:08 -0500 Subject: [PATCH 1/3] In test IO utility, restore the old stdin/stdout Instead of restoring `sys.stdin` to `sys.__stdin__`, restore it to whatever it was before we installed out dummy I/O hooks. This is relevant in pytest, for example, which installs its *own* `sys.stdin`, which we were then clobbering. This was leading to the suppression of test failures observed in #5021 and addressed in #5027. --- test/_common.py | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/test/_common.py b/test/_common.py index 01839e96f8..adddbeea9e 100644 --- a/test/_common.py +++ b/test/_common.py @@ -332,6 +332,7 @@ class DummyIO: def __init__(self): self.stdout = DummyOut() self.stdin = DummyIn(self.stdout) + self.installed = False def addinput(self, s): self.stdin.add(s) @@ -345,12 +346,18 @@ def readcount(self): return self.stdin.reads def install(self): + self.installed = True + + self.orig_stdin = sys.stdin + self.orig_stdout = sys.stdout + sys.stdin = self.stdin sys.stdout = self.stdout def restore(self): - sys.stdin = sys.__stdin__ - sys.stdout = sys.__stdout__ + if self.installed: + sys.stdin = self.orig_stdin + sys.stdout = self.orig_stdout # Utility. From 41d51209199dd3a4b13714180f7d9c90948e1895 Mon Sep 17 00:00:00 2001 From: Adrian Sampson Date: Mon, 18 Dec 2023 17:19:36 -0500 Subject: [PATCH 2/3] DummyIO: Check for double "installs" --- test/_common.py | 1 + 1 file changed, 1 insertion(+) diff --git a/test/_common.py b/test/_common.py index adddbeea9e..a2ae97ba2e 100644 --- a/test/_common.py +++ b/test/_common.py @@ -346,6 +346,7 @@ def readcount(self): return self.stdin.reads def install(self): + assert not self.installed, "DummyIO already installed" self.installed = True self.orig_stdin = sys.stdin From a359cacf6db62e49d8a6619e6bc6ea2e37a4f18c Mon Sep 17 00:00:00 2001 From: Phillip Julien Date: Thu, 14 Dec 2023 20:06:56 -0500 Subject: [PATCH 3/3] Fix failing test: test_nonexistant_db Resolves #5027: failing test: test_nonexistant_db This test was failing because it was requesting input from the user on stdin. This diff mocks stdin with a canned response. --- test/test_ui.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/test/test_ui.py b/test/test_ui.py index cae8614803..a3f92b12e2 100644 --- a/test/test_ui.py +++ b/test/test_ui.py @@ -937,7 +937,8 @@ def test_nonexistant_db(self): config.write("library: /xxx/yyy/not/a/real/path") with self.assertRaises(ui.UserError): - self.run_command("test", lib=None) + with control_stdin("n"): + self.run_command("test", lib=None) def test_user_config_file(self): with self.write_config_file() as file: