From 0aa6c7b83f01656344f05da82ba93d308d5f8cd0 Mon Sep 17 00:00:00 2001 From: Ryan Petrello Date: Wed, 31 Jan 2018 15:12:59 -0500 Subject: [PATCH] remove some leaky mock.patch() that were causing sporadic test failures --- awx/main/tests/unit/test_tasks.py | 17 +++++++---------- 1 file changed, 7 insertions(+), 10 deletions(-) diff --git a/awx/main/tests/unit/test_tasks.py b/awx/main/tests/unit/test_tasks.py index 2b24c18325..2c42df686a 100644 --- a/awx/main/tests/unit/test_tasks.py +++ b/awx/main/tests/unit/test_tasks.py @@ -29,6 +29,7 @@ from awx.main.models import ( ProjectUpdate, UnifiedJob, User, + Organization, build_safe_env ) @@ -204,7 +205,6 @@ class TestJobExecution: mock.patch.object(Project, 'get_project_path', lambda *a, **kw: self.project_path), # don't emit websocket statuses; they use the DB and complicate testing mock.patch.object(UnifiedJob, 'websocket_emit_status', mock.Mock()), - mock.patch.object(Job, 'ansible_virtualenv_path', settings.ANSIBLE_VENV_PATH), mock.patch('awx.main.expect.run.run_pexpect', self.run_pexpect), ] for cls in (Job, AdHocCommand): @@ -267,6 +267,8 @@ class TestJobExecution: self.patches.append(patch) patch.start() + job.project = Project(organization=Organization()) + return job @property @@ -353,11 +355,9 @@ class TestGenericRun(TestJobExecution): def test_valid_custom_virtualenv(self): with TemporaryDirectory(dir=settings.BASE_VENV_PATH) as tempdir: + self.instance.project.custom_virtualenv = tempdir os.makedirs(os.path.join(tempdir, 'lib')) os.makedirs(os.path.join(tempdir, 'bin', 'activate')) - venv_patch = mock.patch.object(Job, 'ansible_virtualenv_path', tempdir) - self.patches.append(venv_patch) - venv_patch.start() self.task.run(self.pk) @@ -371,14 +371,11 @@ class TestGenericRun(TestJobExecution): assert '--ro-bind {} {}'.format(path, path) in ' '.join(args) def test_invalid_custom_virtualenv(self): - venv_patch = mock.patch.object(Job, 'ansible_virtualenv_path', '/venv/missing') - self.patches.append(venv_patch) - venv_patch.start() - with pytest.raises(Exception): + self.instance.project.custom_virtualenv = '/venv/missing' self.task.run(self.pk) - tb = self.task.update_model.call_args[-1]['result_traceback'] - assert 'a valid Python virtualenv does not exist at /venv/missing' in tb + tb = self.task.update_model.call_args[-1]['result_traceback'] + assert 'a valid Python virtualenv does not exist at /venv/missing' in tb class TestAdhocRun(TestJobExecution):