File tree Expand file tree Collapse file tree 2 files changed +32
-1
lines changed Expand file tree Collapse file tree 2 files changed +32
-1
lines changed Original file line number Diff line number Diff line change 77from django .dispatch import receiver
88from django .test .signals import setting_changed
99
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+
1019CONFIG_DEFAULTS = {
1120 # Toolbar options
1221 "DISABLE_PANELS" : {
4453 "SQL_WARNING_THRESHOLD" : 500 , # milliseconds
4554 "OBSERVE_REQUEST_CALLBACK" : "debug_toolbar.toolbar.observe_request" ,
4655 "TOOLBAR_LANGUAGE" : None ,
47- "IS_RUNNING_TESTS" : "test" in sys . argv or "PYTEST_VERSION" in os . environ ,
56+ "IS_RUNNING_TESTS" : _is_running_tests () ,
4857 "UPDATE_ON_FETCH" : False ,
4958}
5059
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