From 74c95b3c9161fc3ee10b5ab008d20fa4293da73f Mon Sep 17 00:00:00 2001 From: Tomas Kubla Date: Tue, 6 Feb 2024 13:12:38 +0100 Subject: [PATCH 1/4] Set PYTHONWARNINGS=error --- docker/entrypoint-integration-tests.sh | 3 +++ docker/entrypoint-unit-tests-devDocker.sh | 3 +++ docker/entrypoint-unit-tests.sh | 3 +++ 3 files changed, 9 insertions(+) diff --git a/docker/entrypoint-integration-tests.sh b/docker/entrypoint-integration-tests.sh index 0044d0b5b9e..5a75ed6b5b7 100755 --- a/docker/entrypoint-integration-tests.sh +++ b/docker/entrypoint-integration-tests.sh @@ -29,6 +29,9 @@ export CHROMEDRIVER CHROME_PATH=/opt/chrome/chrome export CHROME_PATH +# We are strict about Warnings during testing +export PYTHONWARNINGS=error + # Run available unittests with a simple setup # All available Integrationtest Scripts are activated below # If successsful, A successs message is printed and the script continues diff --git a/docker/entrypoint-unit-tests-devDocker.sh b/docker/entrypoint-unit-tests-devDocker.sh index e2c63c04fd9..96f9906c177 100755 --- a/docker/entrypoint-unit-tests-devDocker.sh +++ b/docker/entrypoint-unit-tests-devDocker.sh @@ -15,6 +15,9 @@ unset DD_DATABASE_URL # Unset the celery broker URL so that we can force the other DD_CELERY_BROKER settings unset DD_CELERY_BROKER_URL +# We are strict about Warnings during testing +export PYTHONWARNINGS=error + python3 manage.py makemigrations dojo python3 manage.py migrate diff --git a/docker/entrypoint-unit-tests.sh b/docker/entrypoint-unit-tests.sh index 99062aff8a0..16a5e6c29b5 100755 --- a/docker/entrypoint-unit-tests.sh +++ b/docker/entrypoint-unit-tests.sh @@ -16,6 +16,9 @@ unset DD_DATABASE_URL # Unset the celery broker URL so that we can force the other DD_CELERY_BROKER settings unset DD_CELERY_BROKER_URL +# We are strict about Warnings during testing +export PYTHONWARNINGS=error + # TARGET_SETTINGS_FILE=dojo/settings/settings.py # if [ ! -f ${TARGET_SETTINGS_FILE} ]; then # echo "Creating settings.py" From 70c1d31948c9da0aefc37b1f03d98a41ee6cccfe Mon Sep 17 00:00:00 2001 From: Tomas Kubla Date: Tue, 6 Feb 2024 17:20:00 +0100 Subject: [PATCH 2/4] Add basic filterwarnings --- dojo/settings/settings.dist.py | 8 ++++++++ tests/base_test_class.py | 5 +++++ 2 files changed, 13 insertions(+) diff --git a/dojo/settings/settings.dist.py b/dojo/settings/settings.dist.py index d8eec52a74b..6b16e69bbbe 100644 --- a/dojo/settings/settings.dist.py +++ b/dojo/settings/settings.dist.py @@ -7,6 +7,7 @@ from netaddr import IPNetwork, IPSet import json import logging +import warnings logger = logging.getLogger(__name__) @@ -1714,3 +1715,10 @@ def saml2_attrib_map_format(dict): AUDITLOG_FLUSH_RETENTION_PERIOD = env('DD_AUDITLOG_FLUSH_RETENTION_PERIOD') ENABLE_AUDITLOG = env('DD_ENABLE_AUDITLOG') USE_FIRST_SEEN = env('DD_USE_FIRST_SEEN') + +# TODO - these warnings needs to be removed +if DEBUG: + from django.utils.deprecation import RemovedInDjango50Warning + warnings.filterwarnings("ignore", category=RemovedInDjango50Warning) + warnings.filterwarnings("ignore", message="invalid escape sequence.*") + warnings.filterwarnings("ignore", message="'cgi' is deprecated and slated for removal in Python 3\\.13") diff --git a/tests/base_test_class.py b/tests/base_test_class.py index b9ccf352905..c2f0efdfb13 100644 --- a/tests/base_test_class.py +++ b/tests/base_test_class.py @@ -90,6 +90,11 @@ def setUpClass(cls): print( "starting chromedriver with options: ", vars(dd_driver_options), desired ) + + # TODO - this filter needs to be removed + import warnings + warnings.filterwarnings("ignore", message="executable_path has been deprecated, please pass in a Service object") + dd_driver = webdriver.Chrome( os.environ["CHROMEDRIVER"], chrome_options=dd_driver_options, From 774497521f6a8139616320d3261acf8a92ab2d29 Mon Sep 17 00:00:00 2001 From: Tomas Kubla Date: Tue, 6 Feb 2024 17:44:31 +0100 Subject: [PATCH 3/4] Mute some warnings --- dojo/settings/settings.dist.py | 2 ++ tests/base_test_class.py | 2 ++ 2 files changed, 4 insertions(+) diff --git a/dojo/settings/settings.dist.py b/dojo/settings/settings.dist.py index 6b16e69bbbe..0c13170e74d 100644 --- a/dojo/settings/settings.dist.py +++ b/dojo/settings/settings.dist.py @@ -1722,3 +1722,5 @@ def saml2_attrib_map_format(dict): warnings.filterwarnings("ignore", category=RemovedInDjango50Warning) warnings.filterwarnings("ignore", message="invalid escape sequence.*") warnings.filterwarnings("ignore", message="'cgi' is deprecated and slated for removal in Python 3\\.13") + warnings.filterwarnings("ignore", message="DateTimeField .+ received a naive datetime .+ while time zone support is active\\.") + warnings.filterwarnings("ignore", message="unclosed file .+") diff --git a/tests/base_test_class.py b/tests/base_test_class.py index c2f0efdfb13..8e41f1a9cb4 100644 --- a/tests/base_test_class.py +++ b/tests/base_test_class.py @@ -94,6 +94,8 @@ def setUpClass(cls): # TODO - this filter needs to be removed import warnings warnings.filterwarnings("ignore", message="executable_path has been deprecated, please pass in a Service object") + warnings.filterwarnings("ignore", message="use options instead of chrome_options") + warnings.filterwarnings("ignore", message="desired_capabilities has been deprecated, please pass in a Service object") dd_driver = webdriver.Chrome( os.environ["CHROMEDRIVER"], From 3ddb855b7610853d26e1a02c35cae04f59cce7a0 Mon Sep 17 00:00:00 2001 From: Tomas Kubla Date: Tue, 6 Feb 2024 18:02:55 +0100 Subject: [PATCH 4/4] Mute one more warning --- tests/base_test_class.py | 1 + 1 file changed, 1 insertion(+) diff --git a/tests/base_test_class.py b/tests/base_test_class.py index 8e41f1a9cb4..b5d041d349e 100644 --- a/tests/base_test_class.py +++ b/tests/base_test_class.py @@ -96,6 +96,7 @@ def setUpClass(cls): warnings.filterwarnings("ignore", message="executable_path has been deprecated, please pass in a Service object") warnings.filterwarnings("ignore", message="use options instead of chrome_options") warnings.filterwarnings("ignore", message="desired_capabilities has been deprecated, please pass in a Service object") + warnings.filterwarnings("ignore", message="It is deprecated to return a value that is not None from a test case") dd_driver = webdriver.Chrome( os.environ["CHROMEDRIVER"],