ソースを参照

tests: add helpful decorator to wait before test cleanup

Allow to manual inspect test environment after test fails. This is
similar to --do-not-clean option we had in R3.2.

The decorator should be used only while debugging and should never be
applied to the code committed into repository.
Marek Marczykowski-Górecki 4 年 前
コミット
8ecf00bd0e
1 ファイル変更28 行追加0 行削除
  1. 28 0
      qubes/tests/__init__.py

+ 28 - 0
qubes/tests/__init__.py

@@ -220,6 +220,34 @@ def expectedFailureIfTemplate(templates):
         return wrapper
     return decorator
 
+
+def wait_on_fail(func):
+    """Test decorator for debugging. It pause test execution on failure and wait
+    for user input. It's useful to manually inspect system state just after test
+    fails, before executing any cleanup.
+
+    Usage: decorate a test you are debugging.
+    DO IT ONLY TEMPORARILY, DO NOT COMMIT!
+    """
+
+    @functools.wraps(func)
+    def wrapper(self, *args, **kwargs):
+        try:
+            func(self, *args, **kwargs)
+        except:
+            print('FAIL\n')
+            traceback.print_exc()
+            print('Press return to continue:', end='')
+            sys.stdout.flush()
+            reader = asyncio.StreamReader(loop=self.loop)
+            transport, protocol = self.loop.run_until_complete(
+                self.loop.connect_read_pipe(lambda: asyncio.StreamReaderProtocol(reader),
+                                            sys.stdin))
+            self.loop.run_until_complete(reader.readline())
+            raise
+    return wrapper
+
+
 class _AssertNotRaisesContext(object):
     """A context manager used to implement TestCase.assertNotRaises methods.