From d64e288de793b3abbebfc5beacd426a09d59efa6 Mon Sep 17 00:00:00 2001 From: OpenStack Proposal Bot <openstack-infra@lists.openstack.org> Date: Sun, 12 Jul 2015 15:22:23 +0000 Subject: [PATCH] Updated from global requirements Issue found with mock 1.1.3: Because of the test inheritance test_keypair_import is getting called 3 times. It appears that the mock for open builtins is getting torn down after it's first use, and not correctly built again on subsequent calls. In the gate, this is a race, because we have 3 tests and 8 workers, and this will only fail if 2 or more of the tests happen to be allocated to the same worker. This can be reproduced locally with: tox -e py27 -- --concurrency=1 Converting this to the context manager usage of mock appears to resolve the issue. Co-Authored-By: Sean Dague <sean@dague.net> Related-Bug: https://github.com/testing-cabal/mock/issues/280 Change-Id: I9a87375d2eb6c7cf7b9124b2095a5a4bcc8e7bf3 --- novaclient/tests/unit/v2/test_shell.py | 13 +++++++------ test-requirements.txt | 3 ++- 2 files changed, 9 insertions(+), 7 deletions(-) diff --git a/novaclient/tests/unit/v2/test_shell.py b/novaclient/tests/unit/v2/test_shell.py index 5297697da..e5d8914a5 100644 --- a/novaclient/tests/unit/v2/test_shell.py +++ b/novaclient/tests/unit/v2/test_shell.py @@ -2367,13 +2367,14 @@ class ShellTest(utils.TestCase): {'keypair': {'name': 'test'}}) - @mock.patch.object(builtins, 'open', - mock.mock_open(read_data='FAKE_PUBLIC_KEY')) def test_keypair_import(self): - self.run_command('keypair-add --pub-key test.pub test') - self.assert_called( - 'POST', '/os-keypairs', { - 'keypair': {'public_key': 'FAKE_PUBLIC_KEY', 'name': 'test'}}) + with mock.patch.object(builtins, 'open', + mock.mock_open(read_data='FAKE_PUBLIC_KEY')): + self.run_command('keypair-add --pub-key test.pub test') + self.assert_called( + 'POST', '/os-keypairs', { + 'keypair': {'public_key': 'FAKE_PUBLIC_KEY', + 'name': 'test'}}) def test_keypair_stdin(self): with mock.patch('sys.stdin', six.StringIO('FAKE_PUBLIC_KEY')): diff --git a/test-requirements.txt b/test-requirements.txt index b429932ce..962eb60bf 100644 --- a/test-requirements.txt +++ b/test-requirements.txt @@ -7,7 +7,8 @@ coverage>=3.6 discover fixtures>=1.3.1 keyring!=3.3,>=2.1 -mock>=1.0 +mock>=1.1;python_version!='2.6' +mock==1.0.1;python_version=='2.6' requests-mock>=0.6.0 # Apache-2.0 sphinx!=1.2.0,!=1.3b1,<1.3,>=1.1.2 os-client-config>=1.4.0