Skip to content

Commit 7d89994

Browse files
committed
Ignore the call to the profilers disable method in the ProfilingPanel.
While this hasn't caused any issues with the actual usage of the toolbar, it has caused an unexpected error within the unit tests. This is because the dictionary returned by stats is converted into a list. The order of this list isn't consistent, while the logic expects it to which gave it the random feel to it. Ignoring the call to the disable should cause the view function to be the only function with zero callers.
1 parent fec2fc4 commit 7d89994

File tree

2 files changed

+6
-5
lines changed

2 files changed

+6
-5
lines changed

debug_toolbar/panels/profiling.py

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,14 +10,19 @@
1010
from colorsys import hsv_to_rgb
1111
import os
1212

13+
# Occasionally the disable method on the profiler is listed before
14+
# the actual view functions. This function call should be ignored as
15+
# it leads to an error within the tests.
16+
INVALID_PROFILER_FUNC = "<method 'disable' of '_lsprof.Profiler' objects>"
17+
1318

1419
class DjangoDebugToolbarStats(Stats):
1520
__root = None
1621

1722
def get_root_func(self):
1823
if self.__root is None:
1924
for func, (cc, nc, tt, ct, callers) in self.stats.items():
20-
if len(callers) == 0:
25+
if len(callers) == 0 and INVALID_PROFILER_FUNC not in func:
2126
self.__root = func
2227
break
2328
return self.__root

tests/panels/test_profiling.py

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@
77

88
from ..base import BaseTestCase
99
from ..views import regular_view
10-
from debug_toolbar.compat import unittest
1110

1211

1312
@override_settings(DEBUG_TOOLBAR_PANELS=['debug_toolbar.panels.profiling.ProfilingPanel'])
@@ -17,9 +16,6 @@ def setUp(self):
1716
super(ProfilingPanelTestCase, self).setUp()
1817
self.panel = self.toolbar.get_panel_by_id('ProfilingPanel')
1918

20-
# This test fails randomly for a reason I don't understand.
21-
22-
@unittest.expectedFailure
2319
def test_regular_view(self):
2420
self.panel.process_view(self.request, regular_view, ('profiling',), {})
2521
self.panel.process_response(self.request, self.response)

0 commit comments

Comments
 (0)