From 028a2890b50e8ff4e818d3415536df69faf3a1ed Mon Sep 17 00:00:00 2001 From: Thomas Kowalski Date: Wed, 25 Mar 2026 21:36:17 +0100 Subject: [PATCH 1/2] ci: test on more python versions --- .github/workflows/test.yml | 32 +++++++++++++++------ datadog/api/api_client.py | 6 ++++ tests/integration/dogshell/test_dogshell.py | 2 +- tests/unit/dogstatsd/test_statsd.py | 11 ++++--- 4 files changed, 37 insertions(+), 14 deletions(-) diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index 4f573ccc0..4d4a50384 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -17,19 +17,24 @@ concurrency: jobs: lint: - name: Lint datadogpy files + name: Lint datadogpy files on Python ${{ matrix.python-version }} runs-on: ubuntu-latest + strategy: + fail-fast: false + matrix: + # In the future, we need to add support for Python 2.7 and Python 3.14+ + # but for now, those are failing. + python-version: ['3.8'] steps: - uses: actions/checkout@f43a0e5ff2bd294095638e18286ca9a3d1956744 # v3.6.0 - - name: Set up Python 3.8 + - name: Set up Python ${{ matrix.python-version }} uses: actions/setup-python@7f4fc3e22c37d6ff65e88745f38bd3157c663f7c # v4.9.1 with: - python-version: "3.8" + python-version: ${{ matrix.python-version }} - name: Install dependencies run: | - python -m pip install pre-commit python -m pip install tox # - name: Run black @@ -48,12 +53,12 @@ jobs: fail-fast: false matrix: os: [ubuntu-22.04] - python-version: ['pypy2.7', '3.7', 'pypy3.8'] + # In the future, we need to add support for Python 2.7 and 3.4, as we officially + # support those versions. However, support for those versions has been removed from + # setup-python so we will need to find a workaround. + python-version: ['3.7', '3.8', '3.9', '3.10', '3.11', '3.12', '3.13', '3.14', 'pypy2.7', 'pypy3.8'] # os: [ubuntu-latest, windows-latest, macos-latest] # python-version: ['2.7', '3.7', '3.8', '3.9', '3.10', 'pypy-2.7', 'pypy-3.8'] - env: - TOXENV: ${{ matrix.python-version }} - steps: - uses: actions/checkout@f43a0e5ff2bd294095638e18286ca9a3d1956744 # v3.6.0 @@ -62,7 +67,7 @@ jobs: with: python-version: ${{ matrix.python-version }} - - name: Set constrains for python2.7 + - name: Set constraints for python2.7 # Latest PyYaml supported version for python 2.7 is 5.4.1 which requires # cython<3 to build. See: https://github.com/yaml/pyyaml/issues/724 if: ${{ matrix.python-version == 'pypy2.7' }} @@ -70,6 +75,15 @@ jobs: echo "cython<3" > /tmp/constraints.txt echo "PIP_CONSTRAINT=/tmp/constraints.txt" >> $GITHUB_ENV + - name: Set TOXENV + run: | + version="${{ matrix.python-version }}" + if [[ "$version" == pypy* ]]; then + echo "TOXENV=$version" >> $GITHUB_ENV + else + echo "TOXENV=py${version//./}" >> $GITHUB_ENV + fi + - name: Install tox run: pip install tox diff --git a/datadog/api/api_client.py b/datadog/api/api_client.py index db34873bf..1a64e078f 100644 --- a/datadog/api/api_client.py +++ b/datadog/api/api_client.py @@ -183,6 +183,12 @@ def submit( # Format response content content = result.content + if content and result.headers.get("Content-Encoding") == "gzip": + try: + content = zlib.decompress(content, zlib.MAX_WBITS | 16) + except zlib.error: + pass + if content: try: if is_p3k(): diff --git a/tests/integration/dogshell/test_dogshell.py b/tests/integration/dogshell/test_dogshell.py index a28afee4c..97370356b 100644 --- a/tests/integration/dogshell/test_dogshell.py +++ b/tests/integration/dogshell/test_dogshell.py @@ -56,7 +56,7 @@ def dogshell(capsys, config_file, dog): import click from click.testing import CliRunner - runner = CliRunner(mix_stderr=False) + runner = CliRunner(mix_stderr=False) if sys.version_info[:2] < (3, 10) else CliRunner() @click.command(context_settings={"ignore_unknown_options": True}) @click.argument('args', nargs=-1, type=click.UNPROCESSED) diff --git a/tests/unit/dogstatsd/test_statsd.py b/tests/unit/dogstatsd/test_statsd.py index 34ddea162..43d0a9257 100644 --- a/tests/unit/dogstatsd/test_statsd.py +++ b/tests/unit/dogstatsd/test_statsd.py @@ -1029,11 +1029,14 @@ async def print_foo(): time.sleep(0.5) print("foo") """ - exec(source, {}, locals()) + ns = locals() + exec(source, {}, ns) - loop = asyncio.get_event_loop() - loop.run_until_complete(locals()['print_foo']()) - loop.close() + loop = asyncio.new_event_loop() + try: + loop.run_until_complete(ns['print_foo']()) + finally: + loop.close() # Assert packet = self.recv(2).split("\n")[0] # ignore telemetry packet From 9395e9ab4de1324c75a071fa63919e3a37443382 Mon Sep 17 00:00:00 2001 From: Thomas Kowalski Date: Tue, 7 Apr 2026 16:37:44 +0200 Subject: [PATCH 2/2] test: update Python version for integration tests --- .github/workflows/test.yml | 8 ++++---- .github/workflows/test_integration.yml | 8 ++++---- 2 files changed, 8 insertions(+), 8 deletions(-) diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index 4d4a50384..bb351239e 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -26,10 +26,10 @@ jobs: # but for now, those are failing. python-version: ['3.8'] steps: - - uses: actions/checkout@f43a0e5ff2bd294095638e18286ca9a3d1956744 # v3.6.0 + - uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6.0.2 - name: Set up Python ${{ matrix.python-version }} - uses: actions/setup-python@7f4fc3e22c37d6ff65e88745f38bd3157c663f7c # v4.9.1 + uses: actions/setup-python@a309ff8b426b58ec0e2a45f0f869d46889d02405 # v6.2.0 with: python-version: ${{ matrix.python-version }} @@ -60,10 +60,10 @@ jobs: # os: [ubuntu-latest, windows-latest, macos-latest] # python-version: ['2.7', '3.7', '3.8', '3.9', '3.10', 'pypy-2.7', 'pypy-3.8'] steps: - - uses: actions/checkout@f43a0e5ff2bd294095638e18286ca9a3d1956744 # v3.6.0 + - uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6.0.2 - name: Set up Python ${{ matrix.python-version }} - uses: actions/setup-python@7f4fc3e22c37d6ff65e88745f38bd3157c663f7c # v4.9.1 + uses: actions/setup-python@a309ff8b426b58ec0e2a45f0f869d46889d02405 # v6.2.0 with: python-version: ${{ matrix.python-version }} diff --git a/.github/workflows/test_integration.yml b/.github/workflows/test_integration.yml index ef350352a..ab0a8c179 100644 --- a/.github/workflows/test_integration.yml +++ b/.github/workflows/test_integration.yml @@ -23,12 +23,12 @@ jobs: if: github.event_name == 'pull_request' && github.event.pull_request.draft == false && contains(github.event.pull_request.labels.*.name, 'ci/integrations') steps: - name: Checkout code - uses: actions/checkout@f43a0e5ff2bd294095638e18286ca9a3d1956744 # v3.6.0 + uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6.0.2 - - name: Set up Python 3.7 - uses: actions/setup-python@7f4fc3e22c37d6ff65e88745f38bd3157c663f7c # v4.9.1 + - name: Set up Python 3.9 + uses: actions/setup-python@a309ff8b426b58ec0e2a45f0f869d46889d02405 # v6.2.0 with: - python-version: "3.7" + python-version: "3.9" cache: "pip" - name: Install dependencies