From cda1daf83c7815fa698a3021cf49b05b5e54971e Mon Sep 17 00:00:00 2001 From: Doug Hellmann Date: Fri, 13 Apr 2018 16:12:50 -0400 Subject: [PATCH] set default python to python3 Set the default python to python3 except for the py27 environment. We have to set that explicitly to override the new default. Because flake8 now runs under python 3 there is no built-in name 'file'. Instead we can use the same symbols from the io module to build the spec for mocking out the open() call. The old version of that code that used to only run under python 3 used a private version of the io module, so that is also corrected. Change-Id: I2491e65736d2c79f1134eec6371967c39873891b Signed-off-by: Doug Hellmann --- oslo_vmware/tests/test_service.py | 14 ++++++-------- tox.ini | 5 ++++- 2 files changed, 10 insertions(+), 9 deletions(-) diff --git a/oslo_vmware/tests/test_service.py b/oslo_vmware/tests/test_service.py index 336ef0d0..e20f96dd 100644 --- a/oslo_vmware/tests/test_service.py +++ b/oslo_vmware/tests/test_service.py @@ -13,6 +13,8 @@ # License for the specific language governing permissions and limitations # under the License. +import io + import mock import requests import six @@ -500,16 +502,12 @@ class RequestsTransportTest(base.TestCase): if six.PY3: builtin_open = 'builtins.open' - open_mock = mock.MagicMock(name='file_handle', - spec=open) - import _io - file_spec = list(set(dir(_io.TextIOWrapper)).union( - set(dir(_io.BytesIO)))) else: builtin_open = '__builtin__.open' - open_mock = mock.MagicMock(name='file_handle', - spec=file) - file_spec = file + open_mock = mock.MagicMock(name='file_handle', + spec=open) + file_spec = list(set(dir(io.TextIOWrapper)).union( + set(dir(io.BytesIO)))) file_handle = mock.MagicMock(spec=file_spec) file_handle.write.return_value = None diff --git a/tox.ini b/tox.ini index 795d7f15..cd87fe97 100644 --- a/tox.ini +++ b/tox.ini @@ -3,6 +3,7 @@ minversion = 2.0 envlist = py35,py27,pep8 [testenv] +basepython = python3 install_command = pip install {opts} {packages} whitelist_externals = find rm @@ -12,6 +13,9 @@ deps = -r{toxinidir}/requirements.txt commands = python setup.py testr --slowest --testr-args='{posargs}' +[testenv:py27] +basepython = python2.7 + [testenv:pep8] commands = flake8 @@ -64,7 +68,6 @@ commands = pip-missing-reqs -d --ignore-module=oslo_vmware* --ignore-file=oslo_v commands = sphinx-build -a -E -W -d releasenotes/build/doctrees -b html releasenotes/source releasenotes/build/html [testenv:lower-constraints] -basepython = python3 deps = -c{toxinidir}/lower-constraints.txt -r{toxinidir}/test-requirements.txt