From 4b0cde81fd96dc83b822435013cdc6e4e3f21cac Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Marco=20Trevisan=20=28Trevi=C3=B1o=29?= Date: Thu, 2 Apr 2020 21:24:43 +0200 Subject: [PATCH] tests/fprintd-utils: Add utility function to stop the utility process This avoids addCleanup ordering errors and also errors when we may try to print an invalid stdout pipe (like when we have processed it all), as python might fail with something like: ====================================================================== ERROR: test_fprintd_multiple_verify_fails (__main__.TestFprintdUtilsVerify) ---------------------------------------------------------------------- Traceback (most recent call last): File "~/GNOME/fprintd/tests/test_fprintd_utils.py", line 102, in self.addCleanup(lambda: print(process.stdout.read())) File "/usr/lib/python3.8/codecs.py", line 321, in decode data = self.buffer + input TypeError: can't concat NoneType to bytes --- tests/test_fprintd_utils.py | 15 ++++++++++++--- 1 file changed, 12 insertions(+), 3 deletions(-) diff --git a/tests/test_fprintd_utils.py b/tests/test_fprintd_utils.py index e609b83..129cc25 100755 --- a/tests/test_fprintd_utils.py +++ b/tests/test_fprintd_utils.py @@ -93,15 +93,24 @@ class TestFprintdUtilsBase(dbusmock.DBusTestCase): flags = fcntl.fcntl(process.stdout, fcntl.F_GETFL) fcntl.fcntl(process.stdout, fcntl.F_SETFL, flags | os.O_NONBLOCK) - self.addCleanup(process.wait) - self.addCleanup(process.terminate) - self.addCleanup(lambda: print(process.stdout.read())) + self.addCleanup(self.try_stop_utility_process, process) if sleep: time.sleep(self.sleep_time) return process + def stop_utility_process(self, process): + print(process.stdout.read()) + process.terminate() + process.wait() + + def try_stop_utility_process(self, process): + try: + self.stop_utility_process(process) + except: + pass + def get_process_output(self, process): out = process.stdout.read() self.addCleanup(print, out)