From c218fc2bff5e3ae3fe4dbfe3a20c60e00b11e20a Mon Sep 17 00:00:00 2001 From: Efe Bikmaz <50641281+bikmazefe@users.noreply.github.com> Date: Wed, 14 Aug 2024 14:21:15 +0300 Subject: [PATCH] build(python): Adjust test dependencies for Python versions >= 3.7 [TSI-2469] (#666) * build(python) Adjust test dependencies for Python versions >= 3.7 * Use pytest in test workflow * Fix request mocking for Python <= 3.7 --- .github/workflows/test-python.yml | 2 +- clients/python/test/test_locales_api.py | 7 ++++++- clients/python/test/test_uploads_api.py | 7 ++++++- .../templates/python/test-requirements.mustache | 5 ++++- 4 files changed, 17 insertions(+), 4 deletions(-) diff --git a/.github/workflows/test-python.yml b/.github/workflows/test-python.yml index 2e8b2b82..355b1dd1 100644 --- a/.github/workflows/test-python.yml +++ b/.github/workflows/test-python.yml @@ -18,4 +18,4 @@ jobs: run: | cd ./clients/python pip install -r requirements.txt -r test-requirements.txt - python -m unittest + pytest diff --git a/clients/python/test/test_locales_api.py b/clients/python/test/test_locales_api.py index 0ce1e0f2..d6371c8b 100644 --- a/clients/python/test/test_locales_api.py +++ b/clients/python/test/test_locales_api.py @@ -12,7 +12,12 @@ from __future__ import absolute_import import unittest -from unittest.mock import Mock, patch +import sys + +if sys.version_info[:2] <= (3, 7): + from mock import Mock, patch +else: + from unittest.mock import Mock, patch import phrase_api diff --git a/clients/python/test/test_uploads_api.py b/clients/python/test/test_uploads_api.py index 91289544..8e65d57b 100644 --- a/clients/python/test/test_uploads_api.py +++ b/clients/python/test/test_uploads_api.py @@ -12,7 +12,12 @@ from __future__ import absolute_import import unittest -from unittest.mock import Mock, patch +import sys + +if sys.version_info[:2] <= (3, 7): + from mock import Mock, patch +else: + from unittest.mock import Mock, patch import phrase_api from phrase_api.api.uploads_api import UploadsApi # noqa: E501 diff --git a/openapi-generator/templates/python/test-requirements.mustache b/openapi-generator/templates/python/test-requirements.mustache index 12021b47..9cd7eefa 100644 --- a/openapi-generator/templates/python/test-requirements.mustache +++ b/openapi-generator/templates/python/test-requirements.mustache @@ -6,7 +6,10 @@ py>=1.4.31 randomize>=0.13 {{/useNose}} {{^useNose}} -pytest~=4.6.7 # needed for python 2.7+3.4 pytest-cov>=2.8.1 pytest-randomly==1.2.3 # needed for python 2.7+3.4 + +pytest~=4.6.7; python_version < "3.7" +pytest~=7.1; python_version >= "3.7" +mock; python_version <= "3.7" {{/useNose}} \ No newline at end of file