diff --git a/supertokens_python/supertokens.py b/supertokens_python/supertokens.py index 2988994b7..31bed9b79 100644 --- a/supertokens_python/supertokens.py +++ b/supertokens_python/supertokens.py @@ -170,7 +170,6 @@ def __init__( mode, ) self.supertokens_config = supertokens_config - self.debug = debug if debug is True: enable_debug_logging() self._telemetry_status: str = "NONE" diff --git a/tests/test_logger.py b/tests/test_logger.py index 571a149e6..b7979dfe9 100644 --- a/tests/test_logger.py +++ b/tests/test_logger.py @@ -1,5 +1,6 @@ import importlib import json +import logging import os import sys from datetime import datetime as real_datetime @@ -10,15 +11,26 @@ from supertokens_python import InputAppInfo, SupertokensConfig, init from supertokens_python.constants import VERSION -from supertokens_python.logger import log_debug_message, streamFormatter +from supertokens_python.logger import ( + log_debug_message, + streamFormatter, + NAMESPACE, + enable_debug_logging, +) from supertokens_python.recipe import session from tests.utils import clean_st, reset, setup_st, start_st class LoggerTests(TestCase): - def setup_method(self, _): - self._caplog.clear() + @pytest.fixture(autouse=True) + def inject_fixtures(self, caplog: pytest.LogCaptureFixture): + # caplog is the pytest fixture to capture all logs + self._caplog = caplog # pylint: disable=attribute-defined-outside-init + + def setup_method(self, _): # pylint: disable=no-self-use + # Setting the log level to a higher level so debug logs are not printed + logging.getLogger(NAMESPACE).setLevel(logging.ERROR) reset() clean_st() setup_st() @@ -28,13 +40,9 @@ def teardown_method(self, _): reset() clean_st() - @pytest.fixture(autouse=True) - def inject_fixtures(self, caplog: pytest.LogCaptureFixture): - # caplog is the pytest fixture to capture all logs - self._caplog = caplog # pylint: disable=attribute-defined-outside-init - @patch("supertokens_python.logger.datetime", wraps=real_datetime) - def test_json_msg_format(self, datetime_mock: MagicMock): + def test_1_json_msg_format(self, datetime_mock: MagicMock): + enable_debug_logging() datetime_mock.utcnow.return_value = real_datetime(2000, 1, 1) # type: ignore with self.assertLogs(level="DEBUG") as captured: @@ -47,17 +55,17 @@ def test_json_msg_format(self, datetime_mock: MagicMock): "t": "2000-01-01T00:00Z", "sdkVer": VERSION, "message": "API replied with status 200", - "file": "../tests/test_logger.py:40", + "file": "../tests/test_logger.py:49", } @staticmethod - def test_stream_formatter_format(): + def test_2_stream_formatter_format(): assert ( streamFormatter._fmt # pylint: disable=protected-access == "{name} {message}\n" ) - def test_logger_config_with_debug_true(self): + def test_3_logger_config_with_debug_false(self): start_st() init( supertokens_config=SupertokensConfig("http://localhost:3567"), @@ -69,15 +77,15 @@ def test_logger_config_with_debug_true(self): ), framework="fastapi", recipe_list=[session.init(anti_csrf="VIA_CUSTOM_HEADER")], - debug=True, + debug=False, ) logMsg = "log test - valid log" log_debug_message(logMsg) - assert logMsg in self._caplog.text + assert logMsg not in self._caplog.text - def test_logger_config_with_debug_false(self): + def test_4_logger_config_with_debug_true(self): start_st() init( supertokens_config=SupertokensConfig("http://localhost:3567"), @@ -89,15 +97,15 @@ def test_logger_config_with_debug_false(self): ), framework="fastapi", recipe_list=[session.init(anti_csrf="VIA_CUSTOM_HEADER")], - debug=False, + debug=True, ) logMsg = "log test - valid log" log_debug_message(logMsg) - assert logMsg not in self._caplog.text + assert logMsg in self._caplog.text - def test_logger_config_with_debug_not_set(self): + def test_5_logger_config_with_debug_not_set(self): start_st() init( supertokens_config=SupertokensConfig("http://localhost:3567"), @@ -116,7 +124,7 @@ def test_logger_config_with_debug_not_set(self): assert logMsg not in self._caplog.text - def test_logger_config_with_env_var(self): + def test_6_logger_config_with_env_var(self): os.environ["SUPERTOKENS_DEBUG"] = "1" # environment variable was already set when the logger module was imported