'Setup pristine global configuration and library for testing.
Sets ``beets.config`` so we can safely use any functionality
that uses the global configuration.  All paths used are
contained in a temporary directory
Sets the following properties on itself.
- ``temp_dir`` Path to a temporary directory containing all
files specific to beets
- ``libdir`` Path to a subfolder of ``temp_dir``, containing the
library\'s media files. Same as ``config[\'directory\']``.
- ``config`` The global configuration used by beets.
- ``lib`` Library instance created with the settings from
``config``.
Make sure you call ``teardown_beets()`` afterwards.'

def setup_beets(self, disk=False):

    self.create_temp_dir()
    os.environ['BEETSDIR'] = util.py3_path(self.temp_dir)
    self.config = beets.config
    self.config.clear()
    self.config.read()
    self.config['plugins'] = []
    self.config['verbose'] = 1
    self.config['ui']['color'] = False
    self.config['threaded'] = False
    self.libdir = os.path.join(self.temp_dir, 'libdir')
    os.mkdir(self.libdir)
    self.config['directory'] = util.py3_path(self.libdir)
    if disk:
        dbpath = util.bytestring_path(self.config['library'].as_filename())
    else:
        dbpath = ':memory:'
    self.lib = Library(dbpath, self.libdir)
