tests: fix mixed imports of 'unittest.mock' and 'mock'
The 'mock' package is imported in 'tests.base'. Whenever possible 'tests.base' prefers 'unittest.mock' over 'mock' (which is the case on Python 3.3+). Importing 'mock' together with 'unittest.mock' causes unexpected behavior that results in exceptions when running tests, at least on Python 3.6.12, like: > File "/usr/lib/python3.6/unittest/mock.py", line 1196, in patched > patching.__exit__(*exc_info) > > File "/home/zuul/src/opendev.org/jjb/jenkins-job-builder/.tox/cover/lib/python3.6/site-packages/mock/mock.py", line 1545, in __exit__ > return exit_stack.__exit__(*exc_info) > > File "/usr/lib/python3.6/contextlib.py", line 339, in __exit__ > received_exc = exc_details[0] is not None > > IndexError: tuple index out of range From now on, to avoid similar issues in the future, the 'mock' package is only installed for Python 2.x. Change-Id: Ib3044312f0770735d88d8657d1f953e5a33e771f
This commit is contained in:
parent
7c1c936478
commit
118ac858c4
@ -10,5 +10,5 @@ testscenarios>=0.4 # Apache-2.0/BSD
|
||||
testtools>=1.4.0 # MIT
|
||||
stestr>=2.0.0,!=3.0.0 # Apache-2.0/BSD
|
||||
tox>=2.9.1 # MIT
|
||||
mock>=2.0 # BSD
|
||||
mock>=2.0; python_version < '3.0' # BSD
|
||||
sphinxcontrib-programoutput
|
||||
|
@ -1,13 +1,14 @@
|
||||
import io
|
||||
import os
|
||||
|
||||
from mock import patch
|
||||
from tests.base import mock
|
||||
from tests.cmd.test_cmd import CmdTestsBase
|
||||
|
||||
from jenkins_jobs.cli import entry
|
||||
from jenkins_jobs import builder
|
||||
|
||||
patch = mock.patch
|
||||
|
||||
|
||||
@mock.patch("jenkins_jobs.builder.JenkinsManager.get_plugins_info", mock.MagicMock)
|
||||
class TestConfigs(CmdTestsBase):
|
||||
|
@ -14,7 +14,7 @@
|
||||
# under the License.
|
||||
|
||||
from tests import base
|
||||
import mock
|
||||
from tests.base import mock
|
||||
import os
|
||||
from jenkins_jobs.modules import project_multibranch
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user