diff --git a/avocado/aexpect.py b/avocado/aexpect.py index dbace37eccff78a865bc7696b99a62b1002e1e55..4f62a347ec92a5fdbe5c82df13c9421f91fc8b53 100755 --- a/avocado/aexpect.py +++ b/avocado/aexpect.py @@ -983,7 +983,7 @@ class Tail(Spawn): if _thread_kill_requested: try: os.close(fd) - except: + except Exception: pass return try: diff --git a/avocado/core/output.py b/avocado/core/output.py index 9583b9c13b763ac35a94f4e58dd2522db56612ba..627663fa0bd2edf1eddcae9fd17544cdd76648f4 100644 --- a/avocado/core/output.py +++ b/avocado/core/output.py @@ -54,7 +54,7 @@ class ProgressStreamHandler(logging.StreamHandler): self.flush() except (KeyboardInterrupt, SystemExit): raise - except: + except Exception: self.handleError(record) @@ -89,13 +89,13 @@ class Paginator(object): def close(self): try: self.pipe.close() - except: + except Exception: pass def write(self, msg): try: self.pipe.write(msg) - except: + except Exception: pass diff --git a/avocado/gdb.py b/avocado/gdb.py index c45db7c1f2bf7d5cc53d0a382cba7fe76ed09eca..a0e072db0f522431ca4b66af5b8b7eed25744259 100644 --- a/avocado/gdb.py +++ b/avocado/gdb.py @@ -421,7 +421,7 @@ class GDB(object): # generated by the application being run inside the debugger try: parsed_response = parse_mi(line) - except: + except Exception: cmd.application_output.append(line) continue @@ -660,7 +660,7 @@ class GDBServer(object): c.connect(self.port) connection_ok = True break - except: + except Exception: time.sleep(0.1) c.disconnect() c.exit() diff --git a/avocado/loader.py b/avocado/loader.py index f610297fb5accadd4c8101f8383d6fe5c6f8c22c..af42a1f7a5a9390a6addaac7bdfc246c49ad068a 100644 --- a/avocado/loader.py +++ b/avocado/loader.py @@ -17,16 +17,21 @@ Test loader module. """ +import imp +import inspect import os import re import sys -import imp -import inspect from avocado import test from avocado.core import data_dir from avocado.utils import path +try: + import cStringIO as StringIO +except ImportError: + import StringIO + class _DebugJob(object): @@ -99,7 +104,11 @@ class TestLoader(object): 'base_logdir': self.job.logdir, 'params': params, 'job': self.job} + stdin, stdout, stderr = sys.stdin, sys.stdout, sys.stderr try: + sys.stdin = None + sys.stdout = StringIO.StringIO() + sys.stderr = StringIO.StringIO() f, p, d = imp.find_module(module_name, [test_module_dir]) test_module = imp.load_module(module_name, f, p, d) f.close() @@ -135,7 +144,9 @@ class TestLoader(object): # Since a lot of things can happen here, the broad exception is # justified. The user will get it unadulterated anyway, and avocado # will not crash. - except Exception, details: + except BaseException, details: # Ugly python files can raise any exc + if isinstance(details, KeyboardInterrupt): + raise # Don't ignore ctrl+c if os.access(test_path, os.X_OK): # Module can't be imported, and it's executable. Let's try to # execute it. @@ -159,6 +170,10 @@ class TestLoader(object): params['exception'] = details else: test_class = test.NotATest + finally: + sys.stdin = stdin + sys.stdout = stdout + sys.stderr = stderr sys.path.pop(sys.path.index(test_module_dir)) diff --git a/avocado/plugins/test_list.py b/avocado/plugins/test_list.py index c55804658afc2d9dd0b0f26e384c8573605c66ab..bac589983bd0508aa69112edb4bce141e60b4121 100644 --- a/avocado/plugins/test_list.py +++ b/avocado/plugins/test_list.py @@ -172,5 +172,7 @@ class TestList(plugin.Plugin): self.view.notify(event='error', msg=msg) else: sys.stderr.write(msg) - self.view.cleanup() + finally: + if self.view: + self.view.cleanup() sys.exit(rc) diff --git a/avocado/restclient/connection.py b/avocado/restclient/connection.py index c6e2739d025c3d2fee423720fabd68ac86a5972c..accb9483a6368c1c08ca007f94d47ac4acf15b96 100644 --- a/avocado/restclient/connection.py +++ b/avocado/restclient/connection.py @@ -188,7 +188,7 @@ class Connection(object): """ try: self.request('version') - except: + except Exception: return False return True diff --git a/avocado/settings.py b/avocado/settings.py index 20665343f2165290ede5e6cc46f91435e2457812..faf0cfaa80896c54e39a2e04121173430f9634af 100644 --- a/avocado/settings.py +++ b/avocado/settings.py @@ -89,7 +89,7 @@ def convert_value_type(value, value_type): # strip off leading and trailing white space try: sval = value.strip() - except: + except Exception: sval = value if isinstance(value_type, str): diff --git a/avocado/utils/genio.py b/avocado/utils/genio.py index dc405c80d603247cedc5dcb9cbbad2ef689805c1..cd4f575693640b11d01d346312d524ffb571c32d 100644 --- a/avocado/utils/genio.py +++ b/avocado/utils/genio.py @@ -147,7 +147,7 @@ def read_all_lines(filename): try: with open(filename, 'r') as file_obj: contents = [line.rstrip('\n') for line in file_obj.readlines()] - except: + except Exception: pass return contents diff --git a/avocado/utils/process.py b/avocado/utils/process.py index ee6d55aa0d0e17a47116648860c32cedd7785c2f..53f0caa1438f48cb8f6717f2cd01d4dafaeac23f 100644 --- a/avocado/utils/process.py +++ b/avocado/utils/process.py @@ -687,7 +687,7 @@ class GDBSubProcess(object): try: msgs = self.gdb.read_until_break() messages += msgs - except: + except Exception: pass try: diff --git a/examples/tests/failtest_ugly.py b/examples/tests/failtest_ugly.py new file mode 100644 index 0000000000000000000000000000000000000000..048a735d06e36b877ef28fb766337ea9d86667e5 --- /dev/null +++ b/examples/tests/failtest_ugly.py @@ -0,0 +1,13 @@ +""" +Please don't get inspired by this ugly code +""" +import sys + + +sys.stdout.write("Direct output to stdout\n") +sys.stderr.write("Direct output to stderr\n") +raw_input("I really want some input on each import") +sys.stdin = 'This is my __COOL__ stdin' +sys.stdout = 'my stdout' +sys.stderr = 'my stderr' +sys.exit(-1) # Exit even on import