Merge lp:~vila/bzr/625686-selftest-cleanup-deprecation-warnings into lp:bzr

Proposed by Vincent Ladeuil
Status: Merged
Approved by: Vincent Ladeuil
Approved revision: no longer in the source branch.
Merged at revision: 5399
Proposed branch: lp:~vila/bzr/625686-selftest-cleanup-deprecation-warnings
Merge into: lp:bzr
Diff against target: 139 lines (+40/-16)
4 files modified
NEWS (+3/-0)
bzrlib/builtins.py (+8/-4)
bzrlib/symbol_versioning.py (+29/-11)
bzrlib/versionedfile.py (+0/-1)
To merge this branch: bzr merge lp:~vila/bzr/625686-selftest-cleanup-deprecation-warnings
Reviewer Review Type Date Requested Status
Martin Packman (community) Approve
Review via email: mp+33997@code.launchpad.net

Commit message

Cleanup warnings.filters after running selftest

Description of the change

This fixes bug #625686 by cleaning up the warning filter added by cmd_selftest.

See bug description for details but roughly, cmd_selftest wasn't properly isolated.

This is the least intrusive patch, but we may want to revisit either
blackbox/test_selftest.py design (overrideAtttr may replace get_params_passed_to_core)
or re-think the way we play with warnings.filterwarning (we don't use it much
so it may be overkill though).

Finally, having re-read symbol_versioning.py, I notice that almost all
function there start with 'deprecated'. How about renaming the module
itself to deprecated ?

So instead of writing 'symbol_versioning.deprecated_in()' we can use
the simpler 'deprecated.in()' and so on ?

I'm not sure about how to deprecate the 'symbol_versioning' module itself
in that case though ;)

On the other hand, I'm not sure many plugins depend on it either, thoughts ?

To post a comment you must log in.
Revision history for this message
Martin Packman (gz) wrote :

Change looks good to me. One thing, I'd prefer if you passed and closed over the warnings.filters list as well as well as the tuple just added, to defend against that module global changing.

The warnings module upsets me a little more every time I go near it...

review: Approve
Revision history for this message
Vincent Ladeuil (vila) wrote :

>>>>> Martin [gz] <email address hidden> writes:

    > Review: Approve

    > Change looks good to me. One thing, I'd prefer if you passed and
    > closed over the warnings.filters list as well as well as the tuple
    > just added, to defend against that module global changing.

Hehe, Yeah, me too, but I refrained. I also refrained making
_check_for_filter a bit more precise...

    > The warnings module upsets me a little more every time I go near it...

I think it comes mostly from the fact that we use it only lightly and
mostly as a global state. Yet, some tests want to... test and modify it.

As I said, I went for the minimal patch, but if we encounter more
problems, it will be good to rework the whole. We have several ways to
catch/ignore/activate deprecation warnings (and we even have our own way
to report warnings and our own way to disable them...) and it would good
to unify this (and take python changes into account,
http://docs.python.org/library/warnings.html mentions changes introduced
for 2.6 and 2.7 that we could use a guide).

May be I should add some comments before landing... :)

Revision history for this message
Vincent Ladeuil (vila) wrote :

sent to pqm by email

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'NEWS'
2--- NEWS 2010-08-27 22:09:35 +0000
3+++ NEWS 2010-08-28 15:43:42 +0000
4@@ -103,6 +103,9 @@
5 directory that was a symlink in the previous commit.
6 (Martin Pool, #192859)
7
8+* Fix spurious paramiko warning on hardy by ensuring that ``selftest``
9+ properly remove its warning filter. (Vincent Ladeuil, #625686)
10+
11 * ``HTTP/1.1`` test servers now set a ``Content-Length`` header to comply
12 with pedantic ``HTTP/1.1`` clients. (Vincent Ladeuil, #568421)
13
14
15=== modified file 'bzrlib/builtins.py'
16--- bzrlib/builtins.py 2010-08-20 09:39:20 +0000
17+++ bzrlib/builtins.py 2010-08-28 15:43:42 +0000
18@@ -3572,9 +3572,6 @@
19 parallel=None, lsprof_tests=False):
20 from bzrlib.tests import selftest
21
22- # Make deprecation warnings visible, unless -Werror is set
23- symbol_versioning.activate_deprecation_warnings(override=False)
24-
25 if testspecs_list is not None:
26 pattern = '|'.join(testspecs_list)
27 else:
28@@ -3620,7 +3617,14 @@
29 "starting_with": starting_with
30 }
31 selftest_kwargs.update(self.additional_selftest_args)
32- result = selftest(**selftest_kwargs)
33+
34+ # Make deprecation warnings visible, unless -Werror is set
35+ cleanup = symbol_versioning.activate_deprecation_warnings(
36+ override=False)
37+ try:
38+ result = selftest(**selftest_kwargs)
39+ finally:
40+ cleanup()
41 return int(not result)
42
43
44
45=== modified file 'bzrlib/symbol_versioning.py'
46--- bzrlib/symbol_versioning.py 2010-06-29 16:21:13 +0000
47+++ bzrlib/symbol_versioning.py 2010-08-28 15:43:42 +0000
48@@ -29,6 +29,9 @@
49 'warn',
50 ]
51
52+
53+import warnings
54+# Import the 'warn' symbol so bzrlib can call it even if we redefine it
55 from warnings import warn
56
57 import bzrlib
58@@ -296,7 +299,6 @@
59 :param error_only: Only match an 'error' filter
60 :return: True if a filter is found, False otherwise
61 """
62- import warnings
63 for filter in warnings.filters:
64 if issubclass(DeprecationWarning, filter[2]):
65 # This filter will effect DeprecationWarning
66@@ -305,6 +307,19 @@
67 return False
68
69
70+def _remove_filter_callable(filter):
71+ """Build and returns a callable removing filter from the warnings.
72+
73+ :param filter: The filter to remove (can be None).
74+
75+ :return: A callable that will remove filter from warnings.filters.
76+ """
77+ def cleanup():
78+ if filter:
79+ warnings.filters.remove(filter)
80+ return cleanup
81+
82+
83 def suppress_deprecation_warnings(override=True):
84 """Call this function to suppress all deprecation warnings.
85
86@@ -314,18 +329,17 @@
87
88 :param override: If True, always set the ignore, if False, only set the
89 ignore if there isn't already a filter.
90+
91 :return: A callable to remove the new warnings this added.
92 """
93- import warnings
94 if not override and _check_for_filter(error_only=False):
95 # If there is already a filter effecting suppress_deprecation_warnings,
96 # then skip it.
97- return
98- warnings.filterwarnings('ignore', category=DeprecationWarning)
99- filter = warnings.filters[0]
100- def cleanup():
101- warnings.filters.remove(filter)
102- return cleanup
103+ filter = None
104+ else:
105+ warnings.filterwarnings('ignore', category=DeprecationWarning)
106+ filter = warnings.filters[0]
107+ return _remove_filter_callable(filter)
108
109
110 def activate_deprecation_warnings(override=True):
111@@ -342,10 +356,14 @@
112 :param override: If False, only add a filter if there isn't an error filter
113 already. (This slightly differs from suppress_deprecation_warnings, in
114 because it always overrides everything but -Werror).
115+
116+ :return: A callable to remove the new warnings this added.
117 """
118- import warnings
119 if not override and _check_for_filter(error_only=True):
120 # DeprecationWarnings are already turned into errors, don't downgrade
121 # them to 'default'.
122- return
123- warnings.filterwarnings('default', category=DeprecationWarning)
124+ filter = None
125+ else:
126+ warnings.filterwarnings('default', category=DeprecationWarning)
127+ filter = warnings.filters[0]
128+ return _remove_filter_callable(filter)
129
130=== modified file 'bzrlib/versionedfile.py'
131--- bzrlib/versionedfile.py 2010-08-16 06:46:17 +0000
132+++ bzrlib/versionedfile.py 2010-08-28 15:43:42 +0000
133@@ -46,7 +46,6 @@
134 from bzrlib.transport.memory import MemoryTransport
135 """)
136 from bzrlib.registry import Registry
137-from bzrlib.symbol_versioning import *
138 from bzrlib.textmerge import TextMerge
139 from bzrlib import bencode
140