Merge lp:~jml/launchpad/atexit-warning into lp:launchpad

Proposed by Jonathan Lange
Status: Merged
Approved by: Robert Collins
Approved revision: no longer in the source branch.
Merged at revision: 11804
Proposed branch: lp:~jml/launchpad/atexit-warning
Merge into: lp:launchpad
Diff against target: 62 lines (+10/-4)
2 files modified
lib/canonical/librarian/testing/server.py (+2/-3)
lib/canonical/testing/layers.py (+8/-1)
To merge this branch: bzr merge lp:~jml/launchpad/atexit-warning
Reviewer Review Type Date Requested Status
Robert Collins (community) Approve
Review via email: mp+39403@code.launchpad.net

Commit message

Prevent the atexit warning that occurs when tests are run within the LibrarianLayer.

Description of the change

I'm sick of the atexit warning about the librarian teardown. This patch stops it.

To post a comment you must log in.
Revision history for this message
Robert Collins (lifeless) wrote :

I don't quite follow this, but it makes me nervous. How about removing
the atexit call instead.

Revision history for this message
Robert Collins (lifeless) wrote :

I think you want to None out cls._atexit_call too, and perhaps not it in the class scope as other cls variables are:
        _atexit_call = None

-Rob

review: Approve

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'lib/canonical/librarian/testing/server.py'
2--- lib/canonical/librarian/testing/server.py 2010-09-27 02:08:32 +0000
3+++ lib/canonical/librarian/testing/server.py 2010-10-26 20:58:00 +0000
4@@ -1,4 +1,4 @@
5-# Copyright 2009 Canonical Ltd. This software is licensed under the
6+# Copyright 2009-2010 Canonical Ltd. This software is licensed under the
7 # GNU Affero General Public License version 3 (see the file LICENSE).
8
9 """Fixture for the librarians."""
10@@ -11,9 +11,9 @@
11 'LibrarianTestSetup',
12 ]
13
14+import atexit
15 import os
16 import shutil
17-import tempfile
18 import warnings
19
20 from fixtures import Fixture
21@@ -24,7 +24,6 @@
22 get_pid_from_file,
23 TacException,
24 TacTestSetup,
25- two_stage_kill,
26 )
27 from canonical.librarian.storage import _relFileLocation
28
29
30=== modified file 'lib/canonical/testing/layers.py'
31--- lib/canonical/testing/layers.py 2010-10-22 09:49:44 +0000
32+++ lib/canonical/testing/layers.py 2010-10-26 20:58:00 +0000
33@@ -623,6 +623,8 @@
34
35 _is_setup = False
36
37+ _atexit_call = None
38+
39 @classmethod
40 @profiled
41 def setUp(cls):
42@@ -635,7 +637,7 @@
43 the_librarian = LibrarianTestSetup()
44 the_librarian.setUp()
45 LibrarianLayer._check_and_reset()
46- atexit.register(the_librarian.tearDown)
47+ cls._atexit_call = atexit.register(the_librarian.tearDown)
48
49 @classmethod
50 @profiled
51@@ -650,6 +652,11 @@
52 )
53 LibrarianLayer._check_and_reset()
54 LibrarianTestSetup().tearDown()
55+ # Remove the atexit handler, since we've already done the work.
56+ atexit._exithandlers = [
57+ handler for handler in atexit._exithandlers
58+ if handler[0] != cls._atexit_call]
59+ cls._atexit_call = None
60
61 @classmethod
62 @profiled