mirror of
https://github.com/ansible/awx.git
synced 2026-03-05 10:41:05 -03:30
remove some leaky mock.patch() that were causing sporadic test failures
This commit is contained in:
@@ -29,6 +29,7 @@ from awx.main.models import (
|
|||||||
ProjectUpdate,
|
ProjectUpdate,
|
||||||
UnifiedJob,
|
UnifiedJob,
|
||||||
User,
|
User,
|
||||||
|
Organization,
|
||||||
build_safe_env
|
build_safe_env
|
||||||
)
|
)
|
||||||
|
|
||||||
@@ -204,7 +205,6 @@ class TestJobExecution:
|
|||||||
mock.patch.object(Project, 'get_project_path', lambda *a, **kw: self.project_path),
|
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
|
# don't emit websocket statuses; they use the DB and complicate testing
|
||||||
mock.patch.object(UnifiedJob, 'websocket_emit_status', mock.Mock()),
|
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),
|
mock.patch('awx.main.expect.run.run_pexpect', self.run_pexpect),
|
||||||
]
|
]
|
||||||
for cls in (Job, AdHocCommand):
|
for cls in (Job, AdHocCommand):
|
||||||
@@ -267,6 +267,8 @@ class TestJobExecution:
|
|||||||
self.patches.append(patch)
|
self.patches.append(patch)
|
||||||
patch.start()
|
patch.start()
|
||||||
|
|
||||||
|
job.project = Project(organization=Organization())
|
||||||
|
|
||||||
return job
|
return job
|
||||||
|
|
||||||
@property
|
@property
|
||||||
@@ -353,11 +355,9 @@ class TestGenericRun(TestJobExecution):
|
|||||||
|
|
||||||
def test_valid_custom_virtualenv(self):
|
def test_valid_custom_virtualenv(self):
|
||||||
with TemporaryDirectory(dir=settings.BASE_VENV_PATH) as tempdir:
|
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, 'lib'))
|
||||||
os.makedirs(os.path.join(tempdir, 'bin', 'activate'))
|
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)
|
self.task.run(self.pk)
|
||||||
|
|
||||||
@@ -371,14 +371,11 @@ class TestGenericRun(TestJobExecution):
|
|||||||
assert '--ro-bind {} {}'.format(path, path) in ' '.join(args)
|
assert '--ro-bind {} {}'.format(path, path) in ' '.join(args)
|
||||||
|
|
||||||
def test_invalid_custom_virtualenv(self):
|
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):
|
with pytest.raises(Exception):
|
||||||
|
self.instance.project.custom_virtualenv = '/venv/missing'
|
||||||
self.task.run(self.pk)
|
self.task.run(self.pk)
|
||||||
tb = self.task.update_model.call_args[-1]['result_traceback']
|
tb = self.task.update_model.call_args[-1]['result_traceback']
|
||||||
assert 'a valid Python virtualenv does not exist at /venv/missing' in tb
|
assert 'a valid Python virtualenv does not exist at /venv/missing' in tb
|
||||||
|
|
||||||
|
|
||||||
class TestAdhocRun(TestJobExecution):
|
class TestAdhocRun(TestJobExecution):
|
||||||
|
|||||||
Reference in New Issue
Block a user