from distutils import dir_util
from pytest import fixture
import os


# Adapted from http://stackoverflow.com/a/29631801/2043465
@fixture(scope="function")
def datadir(tmpdir, request):
    '''
    Fixture responsible for searching a folder with the same name of test
    module and, if available, moving all contents to a temporary directory so
    tests can use them freely.
    '''
    filename = request.module.__file__
    test_dir, _ = os.path.splitext(filename)

    if os.path.isdir(test_dir):
        dir_util.copy_tree(test_dir, str(tmpdir))

    return tmpdir

Add pytest fixture for copying files to tmpdir
Add pytest fixture for copying files to tmpdir
