File tree 2 files changed +32
-1
lines changed
2 files changed +32
-1
lines changed Original file line number Diff line number Diff line change 7
7
from django .dispatch import receiver
8
8
from django .test .signals import setting_changed
9
9
10
+
11
+ def _is_running_tests ():
12
+ """
13
+ Helper function to support testing default value for
14
+ IS_RUNNING_TESTS
15
+ """
16
+ return "test" in sys .argv or "PYTEST_VERSION" in os .environ
17
+
18
+
10
19
CONFIG_DEFAULTS = {
11
20
# Toolbar options
12
21
"DISABLE_PANELS" : {
44
53
"SQL_WARNING_THRESHOLD" : 500 , # milliseconds
45
54
"OBSERVE_REQUEST_CALLBACK" : "debug_toolbar.toolbar.observe_request" ,
46
55
"TOOLBAR_LANGUAGE" : None ,
47
- "IS_RUNNING_TESTS" : "test" in sys . argv or "PYTEST_VERSION" in os . environ ,
56
+ "IS_RUNNING_TESTS" : _is_running_tests () ,
48
57
"UPDATE_ON_FETCH" : False ,
49
58
}
50
59
Original file line number Diff line number Diff line change
1
+ from unittest .mock import patch
2
+
3
+ from django .test import TestCase
4
+
5
+ from debug_toolbar .settings import _is_running_tests
6
+
7
+
8
+ class SettingsTestCase (TestCase ):
9
+ @patch ("debug_toolbar.settings.sys" )
10
+ @patch ("debug_toolbar.settings.os" )
11
+ def test_is_running_tests (self , mock_os , mock_sys ):
12
+ mock_sys .argv = "test"
13
+ mock_os .environ = {}
14
+ self .assertTrue (_is_running_tests ())
15
+
16
+ mock_sys .argv = ""
17
+ mock_os .environ = {}
18
+ self .assertFalse (_is_running_tests ())
19
+
20
+ mock_sys .argv = ""
21
+ mock_os .environ = {"PYTEST_VERSION" : "1" }
22
+ self .assertTrue (_is_running_tests ())
You can’t perform that action at this time.
0 commit comments