Show More
@@ -874,6 +874,8 b' class InteractiveShell(SingletonConfigurable):' | |||
|
874 | 874 | def init_events(self): |
|
875 | 875 | self.events = EventManager(self, available_events) |
|
876 | 876 | |
|
877 | self.events.register("pre_execute", self._clear_warning_registry) | |
|
878 | ||
|
877 | 879 | def register_post_execute(self, func): |
|
878 | 880 | """DEPRECATED: Use ip.events.register('post_run_cell', func) |
|
879 | 881 | |
@@ -883,6 +885,13 b' class InteractiveShell(SingletonConfigurable):' | |||
|
883 | 885 | "ip.events.register('post_run_cell', func) instead.") |
|
884 | 886 | self.events.register('post_run_cell', func) |
|
885 | 887 | |
|
888 | def _clear_warning_registry(self): | |
|
889 | # clear the warning registry, so that different code blocks with | |
|
890 | # overlapping line number ranges don't cause spurious suppression of | |
|
891 | # warnings (see gh-6611 for details) | |
|
892 | if "__warningregistry__" in self.user_global_ns: | |
|
893 | del self.user_global_ns["__warningregistry__"] | |
|
894 | ||
|
886 | 895 | #------------------------------------------------------------------------- |
|
887 | 896 | # Things related to the "main" module |
|
888 | 897 | #------------------------------------------------------------------------- |
@@ -843,3 +843,17 b' class TestSyntaxErrorTransformer(unittest.TestCase):' | |||
|
843 | 843 | |
|
844 | 844 | |
|
845 | 845 | |
|
846 | def test_warning_suppression(): | |
|
847 | ip.run_cell("import warnings") | |
|
848 | try: | |
|
849 | with tt.AssertPrints("UserWarning: asdf", channel="stderr"): | |
|
850 | ip.run_cell("warnings.warn('asdf')") | |
|
851 | # Here's the real test -- if we run that again, we should get the | |
|
852 | # warning again. Traditionally, each warning was only issued once per | |
|
853 | # IPython session (approximately), even if the user typed in new and | |
|
854 | # different code that should have also triggered the warning, leading | |
|
855 | # to much confusion. | |
|
856 | with tt.AssertPrints("UserWarning: asdf", channel="stderr"): | |
|
857 | ip.run_cell("warnings.warn('asdf')") | |
|
858 | finally: | |
|
859 | ip.run_cell("del warnings") |
General Comments 0
You need to be logged in to leave comments.
Login now