Repository: Lazarus-org/django_logging (language: python)

Issue:
Ensure Tests Skip on Python Versions Lower than 3.8
Certain tests in the `django_logging` package rely on features only available in Python 3.8 and above. To ensure compatibility across different environments, these tests should be skipped automatically when running on Python versions lower than 3.8. This prevents unnecessary failures in CI/CD pipelines or local environments that might still be using older Python versions.

**Tasks:**
1. Use the `pytest.mark.skipif` to conditionally skip tests on Python versions lower than 3.8.
2. Define a constants file that includes required python version


Discussion / hints:
@MEHRSHAD-MIRSHEKARY 
Yeah that's a good idea 

Fix patch:
diff --git a/.github/workflow/ci.yml b/.github/workflows/ci.yml
similarity index 100%
rename from .github/workflow/ci.yml
rename to .github/workflows/ci.yml
diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml
index 0f38048..898970b 100644
--- a/.pre-commit-config.yaml
+++ b/.pre-commit-config.yaml
@@ -38,9 +38,9 @@ repos:
       - id: commitizen
         exclude: (tests/|docs/).*
 
-  - repo: https://github.com/PyCQA/bandit
-    rev: 1.7.4
-    hooks:
-      - id: bandit
-        args: [ "-c pyproject.toml" ]
-        additional_dependencies: [ "toml" ]
+#  - repo: https://github.com/PyCQA/bandit
+#    rev: 1.7.4
+#    hooks:
+#      - id: bandit
+#        args: [ "-c pyproject.toml" ]
+#        additional_dependencies: [ "toml" ]


Test patch:
diff --git a/tests/commands/test_send_logs.py b/tests/commands/test_send_logs.py
index f4ed85e..d7ef1c5 100644
--- a/tests/commands/test_send_logs.py
+++ b/tests/commands/test_send_logs.py
@@ -1,5 +1,6 @@
 import os
 import shutil
+import sys
 import tempfile
 from unittest.mock import ANY, Mock, patch
 
@@ -8,7 +9,13 @@
 from django.core.management import call_command
 from django.test import TestCase
 
-pytestmark = [pytest.mark.commands, pytest.mark.commands_send_logs]
+from tests.constants import PYTHON_VERSION, PYTHON_VERSION_REASON
+
+pytestmark = [
+    pytest.mark.commands,
+    pytest.mark.commands_send_logs,
+    pytest.mark.skipif(sys.version_info < PYTHON_VERSION, reason=PYTHON_VERSION_REASON),
+]
 
 
 class SendLogsCommandTests(TestCase):
diff --git a/tests/constants.py b/tests/constants.py
new file mode 100644
index 0000000..c2cde2a
--- /dev/null
+++ b/tests/constants.py
@@ -0,0 +1,2 @@
+PYTHON_VERSION = (3, 8)
+PYTHON_VERSION_REASON = "Requires Python 3.8 or higher"
diff --git a/tests/filters/test_log_level_filter.py b/tests/filters/test_log_level_filter.py
index ef389fe..a876147 100644
--- a/tests/filters/test_log_level_filter.py
+++ b/tests/filters/test_log_level_filter.py
@@ -1,10 +1,16 @@
 import logging
+import sys
 
 import pytest
 
 from django_logging.filters import LoggingLevelFilter
+from tests.constants import PYTHON_VERSION, PYTHON_VERSION_REASON
 
-pytestmark = [pytest.mark.filters, pytest.mark.filters_level_filter]
+pytestmark = [
+    pytest.mark.filters,
+    pytest.mark.filters_level_filter,
+    pytest.mark.skipif(sys.version_info < PYTHON_VERSION, reason=PYTHON_VERSION_REASON),
+]
 
 
 class TestLoggingLevelFilter:
diff --git a/tests/formatters/test_colored_formatter.py b/tests/formatters/test_colored_formatter.py
index fe4682a..091306e 100644
--- a/tests/formatters/test_colored_formatter.py
+++ b/tests/formatters/test_colored_formatter.py
@@ -1,11 +1,17 @@
 import logging
+import sys
 from unittest.mock import MagicMock, patch
 
 import pytest
 
 from django_logging.formatters import ColoredFormatter
+from tests.constants import PYTHON_VERSION, PYTHON_VERSION_REASON
 
-pytestmark = [pytest.mark.formatters, pytest.mark.colored_formatter]
+pytestmark = [
+    pytest.mark.formatters,
+    pytest.mark.colored_formatter,
+    pytest.mark.skipif(sys.version_info < PYTHON_VERSION, reason=PYTHON_VERSION_REASON),
+]
 
 
 class TestColoredFormatter:
diff --git a/tests/handlers/test_email_handler.py b/tests/handlers/test_email_handler.py
index 45c37ea..c27c103 100644
--- a/tests/handlers/test_email_handler.py
+++ b/tests/handlers/test_email_handler.py
@@ -1,12 +1,18 @@
 import logging
+import sys
 from unittest.mock import ANY, MagicMock, patch
 
 import pytest
 from django.conf import settings
 
 from django_logging.handlers.email_handler import EmailHandler
+from tests.constants import PYTHON_VERSION, PYTHON_VERSION_REASON
 
-pytestmark = [pytest.mark.handlers, pytest.mark.email_handler]
+pytestmark = [
+    pytest.mark.handlers,
+    pytest.mark.email_handler,
+    pytest.mark.skipif(sys.version_info < PYTHON_VERSION, reason=PYTHON_VERSION_REASON),
+]
 
 
 class TestEmailHandler:
diff --git a/tests/middleware/test_request_middleware.py b/tests/middleware/test_request_middleware.py
index eecb50f..be4b38d 100644
--- a/tests/middleware/test_request_middleware.py
+++ b/tests/middleware/test_request_middleware.py
@@ -1,4 +1,5 @@
 import logging
+import sys
 from unittest.mock import Mock
 
 import pytest
@@ -7,8 +8,13 @@
 from django.test import RequestFactory
 
 from django_logging.middleware import RequestLogMiddleware
+from tests.constants import PYTHON_VERSION, PYTHON_VERSION_REASON
 
-pytestmark = [pytest.mark.middleware, pytest.mark.request_middleware]
+pytestmark = [
+    pytest.mark.middleware,
+    pytest.mark.request_middleware,
+    pytest.mark.skipif(sys.version_info < PYTHON_VERSION, reason=PYTHON_VERSION_REASON),
+]
 
 
 class TestRequestMiddleware:
diff --git a/tests/settings/test_checks.py b/tests/settings/test_checks.py
index 8668bbf..99a45c4 100644
--- a/tests/settings/test_checks.py
+++ b/tests/settings/test_checks.py
@@ -1,3 +1,4 @@
+import sys
 from typing import Generator, List
 from unittest.mock import patch
 
@@ -6,8 +7,13 @@
 from django.core.checks import Error
 
 from django_logging.settings.checks import check_logging_settings
+from tests.constants import PYTHON_VERSION, PYTHON_VERSION_REASON
 
-pytestmark = [pytest.mark.settings, pytest.mark.settings_checks]
+pytestmark = [
+    pytest.mark.settings,
+    pytest.mark.settings_checks,
+    pytest.mark.skipif(sys.version_info < PYTHON_VERSION, reason=PYTHON_VERSION_REASON),
+]
 
 
 class TestChecks:
diff --git a/tests/settings/test_conf.py b/tests/settings/test_conf.py
index 14b1e2f..903408b 100644
--- a/tests/settings/test_conf.py
+++ b/tests/settings/test_conf.py
@@ -1,4 +1,5 @@
 import os
+import sys
 from shutil import rmtree
 from unittest import mock
 
@@ -6,8 +7,13 @@
 
 from django_logging.constants import FORMAT_OPTIONS
 from django_logging.settings.conf import LogConfig, LogManager
+from tests.constants import PYTHON_VERSION, PYTHON_VERSION_REASON
 
-pytestmark = [pytest.mark.settings, pytest.mark.settings_conf]
+pytestmark = [
+    pytest.mark.settings,
+    pytest.mark.settings_conf,
+    pytest.mark.skipif(sys.version_info < PYTHON_VERSION, reason=PYTHON_VERSION_REASON),
+]
 
 
 class TestConf:
diff --git a/tests/utils/test_context_manager.py b/tests/utils/test_context_manager.py
index a758130..e174610 100644
--- a/tests/utils/test_context_manager.py
+++ b/tests/utils/test_context_manager.py
@@ -1,11 +1,17 @@
 import logging
+import sys
 from unittest import mock
 
 import pytest
 
 from django_logging.utils.context_manager import _restore_logging_config, config_setup
+from tests.constants import PYTHON_VERSION, PYTHON_VERSION_REASON
 
-pytestmark = [pytest.mark.utils, pytest.mark.utils_context_manager]
+pytestmark = [
+    pytest.mark.utils,
+    pytest.mark.utils_context_manager,
+    pytest.mark.skipif(sys.version_info < PYTHON_VERSION, reason=PYTHON_VERSION_REASON),
+]
 
 
 class TestContextManager:
diff --git a/tests/utils/test_email_notifier.py b/tests/utils/test_email_notifier.py
index c0997b1..1cabca8 100644
--- a/tests/utils/test_email_notifier.py
+++ b/tests/utils/test_email_notifier.py
@@ -1,3 +1,4 @@
+import sys
 import threading
 from smtplib import SMTPException
 from unittest.mock import ANY, MagicMock
@@ -5,8 +6,13 @@
 import pytest
 
 from django_logging.utils.log_email_notifier.notifier import send_email_async
+from tests.constants import PYTHON_VERSION, PYTHON_VERSION_REASON
 
-pytestmark = [pytest.mark.utils, pytest.mark.utils_email_notifier]
+pytestmark = [
+    pytest.mark.utils,
+    pytest.mark.utils_email_notifier,
+    pytest.mark.skipif(sys.version_info < PYTHON_VERSION, reason=PYTHON_VERSION_REASON),
+]
 
 
 class TestEmailNotifier:
diff --git a/tests/utils/test_get_conf.py b/tests/utils/test_get_conf.py
index cf00904..99558ff 100644
--- a/tests/utils/test_get_conf.py
+++ b/tests/utils/test_get_conf.py
@@ -1,3 +1,4 @@
+import sys
 from typing import Dict
 from unittest.mock import patch
 
@@ -10,8 +11,13 @@
     is_initialization_message_enabled,
     use_email_notifier_template,
 )
+from tests.constants import PYTHON_VERSION, PYTHON_VERSION_REASON
 
-pytestmark = [pytest.mark.utils, pytest.mark.utils_get_conf]
+pytestmark = [
+    pytest.mark.utils,
+    pytest.mark.utils_get_conf,
+    pytest.mark.skipif(sys.version_info < PYTHON_VERSION, reason=PYTHON_VERSION_REASON),
+]
 
 
 class TestGetConf:
diff --git a/tests/utils/test_log_and_notify.py b/tests/utils/test_log_and_notify.py
index 2bd2dc3..c3a86fa 100644
--- a/tests/utils/test_log_and_notify.py
+++ b/tests/utils/test_log_and_notify.py
@@ -1,4 +1,5 @@
 import logging
+import sys
 from typing import Dict
 from unittest.mock import MagicMock, patch
 
@@ -6,8 +7,13 @@
 from django.conf import settings
 
 from django_logging.utils.log_email_notifier.log_and_notify import log_and_notify_admin
+from tests.constants import PYTHON_VERSION, PYTHON_VERSION_REASON
 
-pytestmark = [pytest.mark.utils, pytest.mark.utils_log_and_notify]
+pytestmark = [
+    pytest.mark.utils,
+    pytest.mark.utils_log_and_notify,
+    pytest.mark.skipif(sys.version_info < PYTHON_VERSION, reason=PYTHON_VERSION_REASON),
+]
 
 
 class TestLogAndNotify:
diff --git a/tests/utils/test_set_conf.py b/tests/utils/test_set_conf.py
index e8d061e..5aaebb1 100644
--- a/tests/utils/test_set_conf.py
+++ b/tests/utils/test_set_conf.py
@@ -1,12 +1,18 @@
 import os
+import sys
 from unittest.mock import MagicMock, patch
 
 import pytest
 
 from django_logging.constants.ansi_colors import AnsiColors
 from django_logging.utils.set_conf import set_config
+from tests.constants import PYTHON_VERSION, PYTHON_VERSION_REASON
 
-pytestmark = [pytest.mark.utils, pytest.mark.utils_set_conf]
+pytestmark = [
+    pytest.mark.utils,
+    pytest.mark.utils_set_conf,
+    pytest.mark.skipif(sys.version_info < PYTHON_VERSION, reason=PYTHON_VERSION_REASON),
+]
 
 
 class TestSetConf:
diff --git a/tests/validators/test_config_validators.py b/tests/validators/test_config_validators.py
index 570f57e..f344c55 100644
--- a/tests/validators/test_config_validators.py
+++ b/tests/validators/test_config_validators.py
@@ -1,3 +1,4 @@
+import sys
 from unittest.mock import patch
 
 import pytest
@@ -12,8 +13,13 @@
     validate_format_string,
     validate_log_levels,
 )
+from tests.constants import PYTHON_VERSION, PYTHON_VERSION_REASON
 
-pytestmark = [pytest.mark.validators, pytest.mark.config_validator]
+pytestmark = [
+    pytest.mark.validators,
+    pytest.mark.config_validator,
+    pytest.mark.skipif(sys.version_info < PYTHON_VERSION, reason=PYTHON_VERSION_REASON),
+]
 
 
 class TestConfigValidator:
diff --git a/tests/validators/test_email_settings_validator.py b/tests/validators/test_email_settings_validator.py
index 30b9d5b..c48ad85 100644
--- a/tests/validators/test_email_settings_validator.py
+++ b/tests/validators/test_email_settings_validator.py
@@ -1,3 +1,4 @@
+import sys
 from typing import Dict
 from unittest.mock import patch
 
@@ -5,8 +6,13 @@
 from django.conf import settings
 
 from django_logging.validators.email_settings_validator import check_email_settings
+from tests.constants import PYTHON_VERSION, PYTHON_VERSION_REASON
 
-pytestmark = [pytest.mark.validators, pytest.mark.email_settings_validator]
+pytestmark = [
+    pytest.mark.validators,
+    pytest.mark.email_settings_validator,
+    pytest.mark.skipif(sys.version_info < PYTHON_VERSION, reason=PYTHON_VERSION_REASON),
+]
 
 
 class TestEmailSettingsValidator: