'Docker container already exists'

def test_container_already_exists(self):

    self.mocks.configure_mock('docker_client', {'inspect_container.return_value': {'State': {'Running': True}}, 'exec_create.return_value': {'Id': 'container-foobar'}, 'exec_start.return_value': 'This    is    the    return', 'exec_inspect.return_value': {'ExitCode': 0}})
    build_env = DockerEnvironment(version=self.version, project=self.project, build={'id': DUMMY_BUILD_ID})
    def _inner():
        with build_env:
            build_env.run('echo', 'test', cwd='/tmp')
    self.assertRaises(BuildEnvironmentError, _inner)
    self.assertEqual(str(build_env.failure), 'A    build    environment    is    currently    running    for    this    version')
    self.assertEqual(self.mocks.docker_client.exec_create.call_count, 0)
    self.assertTrue(build_env.failed)
    self.assertFalse(self.mocks.api()(DUMMY_BUILD_ID).put.called)
