Skip to content

Commit

Permalink
Be strict about Warnings during testing (#9490)
Browse files Browse the repository at this point in the history
* Set PYTHONWARNINGS=error

* Add basic filterwarnings

* Mute some warnings

* Mute one more warning
  • Loading branch information
kiblik authored Feb 6, 2024
1 parent e76c968 commit 4bdcccf
Show file tree
Hide file tree
Showing 5 changed files with 27 additions and 0 deletions.
3 changes: 3 additions & 0 deletions docker/entrypoint-integration-tests.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
3 changes: 3 additions & 0 deletions docker/entrypoint-unit-tests-devDocker.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
3 changes: 3 additions & 0 deletions docker/entrypoint-unit-tests.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
10 changes: 10 additions & 0 deletions dojo/settings/settings.dist.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
from netaddr import IPNetwork, IPSet
import json
import logging
import warnings

logger = logging.getLogger(__name__)

Expand Down Expand Up @@ -1714,3 +1715,12 @@ 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")
warnings.filterwarnings("ignore", message="DateTimeField .+ received a naive datetime .+ while time zone support is active\\.")
warnings.filterwarnings("ignore", message="unclosed file .+")
8 changes: 8 additions & 0 deletions tests/base_test_class.py
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,14 @@ 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")
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"],
chrome_options=dd_driver_options,
Expand Down

0 comments on commit 4bdcccf

Please sign in to comment.