diff --git a/.github/workflows/test-integration-django.yml b/.github/workflows/test-integration-django.yml index 17a5f6a605..74869b11c9 100644 --- a/.github/workflows/test-integration-django.yml +++ b/.github/workflows/test-integration-django.yml @@ -55,6 +55,7 @@ jobs: SENTRY_PYTHON_TEST_POSTGRES_USER: postgres SENTRY_PYTHON_TEST_POSTGRES_PASSWORD: sentry SENTRY_PYTHON_TEST_POSTGRES_NAME: ci_test + SENTRY_PYTHON_TEST_POSTGRES_HOST: localhost steps: - uses: actions/checkout@v3 @@ -110,6 +111,7 @@ jobs: SENTRY_PYTHON_TEST_POSTGRES_USER: postgres SENTRY_PYTHON_TEST_POSTGRES_PASSWORD: sentry SENTRY_PYTHON_TEST_POSTGRES_NAME: ci_test + SENTRY_PYTHON_TEST_POSTGRES_HOST: postgres steps: - uses: actions/checkout@v3 diff --git a/scripts/split-tox-gh-actions/ci-yaml-services.txt b/scripts/split-tox-gh-actions/ci-yaml-services.txt index 2219e5a4da..01bb9566b0 100644 --- a/scripts/split-tox-gh-actions/ci-yaml-services.txt +++ b/scripts/split-tox-gh-actions/ci-yaml-services.txt @@ -16,3 +16,4 @@ SENTRY_PYTHON_TEST_POSTGRES_USER: postgres SENTRY_PYTHON_TEST_POSTGRES_PASSWORD: sentry SENTRY_PYTHON_TEST_POSTGRES_NAME: ci_test + SENTRY_PYTHON_TEST_POSTGRES_HOST: {{ postgres_host }} diff --git a/scripts/split-tox-gh-actions/split-tox-gh-actions.py b/scripts/split-tox-gh-actions/split-tox-gh-actions.py index 8540b7aaea..2e32672acf 100755 --- a/scripts/split-tox-gh-actions/split-tox-gh-actions.py +++ b/scripts/split-tox-gh-actions/split-tox-gh-actions.py @@ -72,20 +72,25 @@ def write_yaml_file( py27_supported = "2.7" in py_versions test_loc = template.index("{{ test }}\n") - test_snippet = open(TEMPLATE_SNIPPET_TEST, "r").readlines() + f = open(TEMPLATE_SNIPPET_TEST, "r") + test_snippet = f.readlines() template = template[:test_loc] + test_snippet + template[test_loc + 1 :] + f.close() test_py27_loc = template.index("{{ test_py27 }}\n") if py27_supported: - test_py27_snippet = open(TEMPLATE_SNIPPET_TEST_PY27, "r").readlines() + f = open(TEMPLATE_SNIPPET_TEST_PY27, "r") + test_py27_snippet = f.readlines() template = ( template[:test_py27_loc] + test_py27_snippet + template[test_py27_loc + 1 :] ) + f.close() py_versions.remove("2.7") else: template.pop(test_py27_loc) + py27_test_part = False for template_line in template: if template_line.strip() == "{{ strategy_matrix }}": m = MATRIX_DEFINITION @@ -97,7 +102,14 @@ def write_yaml_file( elif template_line.strip() == "{{ services }}": if current_framework in FRAMEWORKS_NEEDING_POSTGRES: f = open(TEMPLATE_FILE_SERVICES, "r") - out += "".join(f.readlines()) + lines = [ + line.replace( + "{{ postgres_host }}", + "postgres" if py27_test_part else "localhost", + ) + for line in f.readlines() + ] + out += "".join(lines) f.close() elif template_line.strip() == "{{ check_needs }}": @@ -111,6 +123,9 @@ def write_yaml_file( out += CHECK_PY27 else: + if template_line.strip() == "test-py27:": + py27_test_part = True + out += template_line.replace("{{ framework }}", current_framework) # write rendered template diff --git a/tests/integrations/django/myapp/settings.py b/tests/integrations/django/myapp/settings.py index e746c96bef..6eab2a2360 100644 --- a/tests/integrations/django/myapp/settings.py +++ b/tests/integrations/django/myapp/settings.py @@ -126,7 +126,7 @@ def middleware(request): "NAME": os.environ["SENTRY_PYTHON_TEST_POSTGRES_NAME"], "USER": os.environ["SENTRY_PYTHON_TEST_POSTGRES_USER"], "PASSWORD": os.environ["SENTRY_PYTHON_TEST_POSTGRES_PASSWORD"], - "HOST": "postgres", + "HOST": os.environ.get("SENTRY_PYTHON_TEST_POSTGRES_HOST", "localhost"), "PORT": 5432, } except (ImportError, KeyError): diff --git a/tox.ini b/tox.ini index 040d6659df..b104d80ac5 100644 --- a/tox.ini +++ b/tox.ini @@ -488,6 +488,7 @@ passenv = SENTRY_PYTHON_TEST_POSTGRES_USER SENTRY_PYTHON_TEST_POSTGRES_PASSWORD SENTRY_PYTHON_TEST_POSTGRES_NAME + SENTRY_PYTHON_TEST_POSTGRES_HOST usedevelop = True extras = bottle: bottle