
import pytest


@pytest.fixture(scope='function')
def back_up_rc(request):
    """
    Back up an existing cookiecutter rc and restore it after the test.
    If ~/.cookiecutterrc is pre-existing, move it to a temp location
    """
    self.user_config_path = os.path.expanduser('~/.cookiecutterrc')
    self.user_config_path_backup = os.path.expanduser(
        '~/.cookiecutterrc.backup'
    )

    if os.path.exists(self.user_config_path):
        shutil.copy(self.user_config_path, self.user_config_path_backup)
        os.remove(self.user_config_path)

    def restore_rc():
        """
        If it existed, restore ~/.cookiecutterrc
        """
        if os.path.exists(self.user_config_path_backup):
            shutil.copy(self.user_config_path_backup, self.user_config_path)
            os.remove(self.user_config_path_backup)
    request.addfinalizer(restore_rc)


import os
import shutil
import pytest


@pytest.fixture(scope='function')
def back_up_rc(request):
    """
    Back up an existing cookiecutter rc and restore it after the test.
    If ~/.cookiecutterrc is pre-existing, move it to a temp location
    """
    user_config_path = os.path.expanduser('~/.cookiecutterrc')
    user_config_path_backup = os.path.expanduser(
        '~/.cookiecutterrc.backup'
    )

    if os.path.exists(user_config_path):
        shutil.copy(user_config_path, user_config_path_backup)
        os.remove(user_config_path)

    def restore_rc():
        """
        If it existed, restore ~/.cookiecutterrc
        """
        if os.path.exists(user_config_path_backup):
            shutil.copy(user_config_path_backup, user_config_path)
            os.remove(user_config_path_backup)
    request.addfinalizer(restore_rc)

Remove self references from setup/teardown
Remove self references from setup/teardown

  
+ import os
+ import shutil
  import pytest
  
  
  @pytest.fixture(scope='function')
  def back_up_rc(request):
      """
      Back up an existing cookiecutter rc and restore it after the test.
      If ~/.cookiecutterrc is pre-existing, move it to a temp location
      """
-     self.user_config_path = os.path.expanduser('~/.cookiecutterrc')
+     user_config_path = os.path.expanduser('~/.cookiecutterrc')
-     self.user_config_path_backup = os.path.expanduser(
+     user_config_path_backup = os.path.expanduser(
          '~/.cookiecutterrc.backup'
      )
  
-     if os.path.exists(self.user_config_path):
+     if os.path.exists(user_config_path):
-         shutil.copy(self.user_config_path, self.user_config_path_backup)
+         shutil.copy(user_config_path, user_config_path_backup)
-         os.remove(self.user_config_path)
+         os.remove(user_config_path)
  
      def restore_rc():
          """
          If it existed, restore ~/.cookiecutterrc
          """
-         if os.path.exists(self.user_config_path_backup):
+         if os.path.exists(user_config_path_backup):
-             shutil.copy(self.user_config_path_backup, self.user_config_path)
+             shutil.copy(user_config_path_backup, user_config_path)
-             os.remove(self.user_config_path_backup)
+             os.remove(user_config_path_backup)
      request.addfinalizer(restore_rc)
  
Remove self references from setup/teardown
## Code Before:

import pytest


@pytest.fixture(scope='function')
def back_up_rc(request):
    """
    Back up an existing cookiecutter rc and restore it after the test.
    If ~/.cookiecutterrc is pre-existing, move it to a temp location
    """
    self.user_config_path = os.path.expanduser('~/.cookiecutterrc')
    self.user_config_path_backup = os.path.expanduser(
        '~/.cookiecutterrc.backup'
    )

    if os.path.exists(self.user_config_path):
        shutil.copy(self.user_config_path, self.user_config_path_backup)
        os.remove(self.user_config_path)

    def restore_rc():
        """
        If it existed, restore ~/.cookiecutterrc
        """
        if os.path.exists(self.user_config_path_backup):
            shutil.copy(self.user_config_path_backup, self.user_config_path)
            os.remove(self.user_config_path_backup)
    request.addfinalizer(restore_rc)

## Instruction:
Remove self references from setup/teardown
## Code After:

import os
import shutil
import pytest


@pytest.fixture(scope='function')
def back_up_rc(request):
    """
    Back up an existing cookiecutter rc and restore it after the test.
    If ~/.cookiecutterrc is pre-existing, move it to a temp location
    """
    user_config_path = os.path.expanduser('~/.cookiecutterrc')
    user_config_path_backup = os.path.expanduser(
        '~/.cookiecutterrc.backup'
    )

    if os.path.exists(user_config_path):
        shutil.copy(user_config_path, user_config_path_backup)
        os.remove(user_config_path)

    def restore_rc():
        """
        If it existed, restore ~/.cookiecutterrc
        """
        if os.path.exists(user_config_path_backup):
            shutil.copy(user_config_path_backup, user_config_path)
            os.remove(user_config_path_backup)
    request.addfinalizer(restore_rc)
