From ca848871da40244c64f3737d247df55c144276b0 Mon Sep 17 00:00:00 2001 From: Tomasz Prus Date: Wed, 24 Nov 2021 08:54:25 +0100 Subject: [PATCH] [Python] Add missing Mock library for Python 2.7. (#10939) * [Python] Add missing Mock library for Python 2.7. * Update template for test-requirements.txt. --- .../resources/python-legacy/test-requirements.mustache | 7 ++++++- .../client/petstore/python-legacy/test-requirements.txt | 1 + .../client/petstore/python-legacy/tests/test_pet_api.py | 7 ++++++- .../client/petstore/python-legacy/test-requirements.txt | 1 + 4 files changed, 14 insertions(+), 2 deletions(-) diff --git a/modules/openapi-generator/src/main/resources/python-legacy/test-requirements.mustache b/modules/openapi-generator/src/main/resources/python-legacy/test-requirements.mustache index 12021b47a1c..a697e6a9e71 100644 --- a/modules/openapi-generator/src/main/resources/python-legacy/test-requirements.mustache +++ b/modules/openapi-generator/src/main/resources/python-legacy/test-requirements.mustache @@ -9,4 +9,9 @@ randomize>=0.13 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 -{{/useNose}} \ No newline at end of file +{{/useNose}} +{{^asyncio}} +{{^tornado}} +mock; python_version<'3.0' +{{/tornado}} +{{/asyncio}} diff --git a/samples/client/petstore/python-legacy/test-requirements.txt b/samples/client/petstore/python-legacy/test-requirements.txt index 4ed3991cbec..96e37c87e98 100644 --- a/samples/client/petstore/python-legacy/test-requirements.txt +++ b/samples/client/petstore/python-legacy/test-requirements.txt @@ -1,3 +1,4 @@ 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 +mock; python_version<'3.0' diff --git a/samples/client/petstore/python-legacy/tests/test_pet_api.py b/samples/client/petstore/python-legacy/tests/test_pet_api.py index 4e894436d4b..f18bdd2dd8f 100644 --- a/samples/client/petstore/python-legacy/tests/test_pet_api.py +++ b/samples/client/petstore/python-legacy/tests/test_pet_api.py @@ -13,7 +13,12 @@ $ nosetests -v import os import unittest -from unittest.mock import patch + +try: + from unittest.mock import patch +except ImportError: + # Python 2.7 + from mock import patch import petstore_api from petstore_api import Configuration diff --git a/samples/openapi3/client/petstore/python-legacy/test-requirements.txt b/samples/openapi3/client/petstore/python-legacy/test-requirements.txt index 4ed3991cbec..96e37c87e98 100755 --- a/samples/openapi3/client/petstore/python-legacy/test-requirements.txt +++ b/samples/openapi3/client/petstore/python-legacy/test-requirements.txt @@ -1,3 +1,4 @@ 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 +mock; python_version<'3.0'