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.
This commit is contained in:
parent
4fa45dbc91
commit
8ecf00bd0e
@ -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.
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user