
import os

import mock
import pytest

PROJECT = os.environ['GCLOUD_PROJECT']


@pytest.fixture
def api_client_inject_project_id():
    """Patches all googleapiclient requests to replace 'YOUR_PROJECT_ID' with
    the project ID."""
    import googleapiclient.http

    old_execute = googleapiclient.http.HttpRequest.execute

    def new_execute(self, http=None, num_retries=0):
        self.uri = self.uri.replace('YOUR_PROJECT_ID', PROJECT)
        return old_execute(self, http=http, num_retries=num_retries)

    with mock.patch(
            'googleapiclient.http.HttpRequest.execute',
            new=new_execute):
        yield


import os

import mock
import pytest

PROJECT = 'python-docs-samples'


@pytest.fixture
def api_client_inject_project_id():
    """Patches all googleapiclient requests to replace 'YOUR_PROJECT_ID' with
    the project ID."""
    import googleapiclient.http

    old_execute = googleapiclient.http.HttpRequest.execute

    def new_execute(self, http=None, num_retries=0):
        self.uri = self.uri.replace('YOUR_PROJECT_ID', PROJECT)
        return old_execute(self, http=http, num_retries=num_retries)

    with mock.patch(
            'googleapiclient.http.HttpRequest.execute',
            new=new_execute):
        yield

Set the Project in code
Set the Project in code

  
  import os
  
  import mock
  import pytest
  
- PROJECT = os.environ['GCLOUD_PROJECT']
+ PROJECT = 'python-docs-samples'
  
  
  @pytest.fixture
  def api_client_inject_project_id():
      """Patches all googleapiclient requests to replace 'YOUR_PROJECT_ID' with
      the project ID."""
      import googleapiclient.http
  
      old_execute = googleapiclient.http.HttpRequest.execute
  
      def new_execute(self, http=None, num_retries=0):
          self.uri = self.uri.replace('YOUR_PROJECT_ID', PROJECT)
          return old_execute(self, http=http, num_retries=num_retries)
  
      with mock.patch(
              'googleapiclient.http.HttpRequest.execute',
              new=new_execute):
          yield
  
Set the Project in code
## Code Before:

import os

import mock
import pytest

PROJECT = os.environ['GCLOUD_PROJECT']


@pytest.fixture
def api_client_inject_project_id():
    """Patches all googleapiclient requests to replace 'YOUR_PROJECT_ID' with
    the project ID."""
    import googleapiclient.http

    old_execute = googleapiclient.http.HttpRequest.execute

    def new_execute(self, http=None, num_retries=0):
        self.uri = self.uri.replace('YOUR_PROJECT_ID', PROJECT)
        return old_execute(self, http=http, num_retries=num_retries)

    with mock.patch(
            'googleapiclient.http.HttpRequest.execute',
            new=new_execute):
        yield

## Instruction:
Set the Project in code
## Code After:

import os

import mock
import pytest

PROJECT = 'python-docs-samples'


@pytest.fixture
def api_client_inject_project_id():
    """Patches all googleapiclient requests to replace 'YOUR_PROJECT_ID' with
    the project ID."""
    import googleapiclient.http

    old_execute = googleapiclient.http.HttpRequest.execute

    def new_execute(self, http=None, num_retries=0):
        self.uri = self.uri.replace('YOUR_PROJECT_ID', PROJECT)
        return old_execute(self, http=http, num_retries=num_retries)

    with mock.patch(
            'googleapiclient.http.HttpRequest.execute',
            new=new_execute):
        yield
