Merge lp:~rvb/maas-test/cleanup-control-c into lp:maas-test

Proposed by Raphaël Badin
Status: Merged
Approved by: Raphaël Badin
Approved revision: 83
Merged at revision: 82
Proposed branch: lp:~rvb/maas-test/cleanup-control-c
Merge into: lp:maas-test
Diff against target: 19 lines (+8/-1)
1 file modified
maastest/main.py (+8/-1)
To merge this branch: bzr merge lp:~rvb/maas-test/cleanup-control-c
Reviewer Review Type Date Requested Status
Gavin Panella (community) Approve
Review via email: mp+197832@code.launchpad.net

Commit message

Call tearDownClass when KeyboardInterrupt is raised.

Description of the change

The VM machine (and other resources) were not cleaned up with a user hit control-c when the tests are running (note that everything is cleaned up all right if control-c is hit during the preparation phase — i.e. when the fixtures are being created).

I looked into using unittest.installHandler / unittest.registerResult(result) which seem to be designed to achieve the same kind of result. I might be wrong but they seem to be better tailored to cope with test-level cleanups and what we have here is class-level cleanups so I think the solution I'm putting out for review here is simpler and fits out particular use-case better; of course, I'm happy to be proven wrong.

To post a comment you must log in.
Revision history for this message
Gavin Panella (allenap) wrote :

This is a band-aid, but then unittest seems to have devolved into a mess; it's hard to do the right thing. This does miss out on test-level and module-level tearDowns, but it's an improvement nonetheless. Perhaps you could add a comment about that to the code?

review: Approve
Revision history for this message
Raphaël Badin (rvb) wrote :

> This is a band-aid, but then unittest seems to have devolved into a mess; it's
> hard to do the right thing. This does miss out on test-level and module-level
> tearDowns, but it's an improvement nonetheless. Perhaps you could add a
> comment about that to the code?

Sure thing, done. Thanks for the review and your work to try improving this code. It didn't pan out, but it's appreciated nonetheless.

Revision history for this message
MAAS Lander (maas-lander) wrote :

There are additional revisions which have not been approved in review. Please seek review and approval of these new revisions.

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'maastest/main.py'
2--- maastest/main.py 2013-11-29 13:22:37 +0000
3+++ maastest/main.py 2013-12-05 12:08:41 +0000
4@@ -53,7 +53,14 @@
5 ConfiguredTestMAAS.configure(args)
6
7 from maastest.console import run_console
8- run_console(ConfiguredTestMAAS)
9+ # This try/except is a band-aid to make sure the fixtures gets cleaned
10+ # up when a KeyboardInterrupt exception is raised.
11+ # This does miss out on test-level and module-level tearDowns.
12+ try:
13+ run_console(ConfiguredTestMAAS)
14+ except KeyboardInterrupt:
15+ ConfiguredTestMAAS.tearDownClass()
16+ raise
17
18
19 if __name__ == '__main__':

Subscribers

People subscribed via source and target branches