

@pytest.fixture(scope='function')
def django_testdir(request, testdir, monkeypatch):
    marker = request.node.get_marker('django_project')
    options = _marker_apifun(**(marker.kwargs if marker else {
        
    }))
    db_engine = get_db_engine()
    if ((db_engine in ('mysql', 'postgresql_psycopg2')) or ((db_engine == 'sqlite3') and (DB_NAME != ':memory:'))):
        create_empty_production_database()
    if hasattr(request.node.cls, 'db_settings'):
        db_settings = request.node.cls.db_settings
    else:
        db_settings = copy.deepcopy(settings.DATABASES)
        db_settings['default']['NAME'] = DB_NAME
    test_settings = (dedent("\n        # Pypy compatibility\n        try:\n            from psycopg2ct import compat\n        except ImportError:\n            pass\n        else:\n            compat.register()\n\n        DATABASES = %(db_settings)s\n\n        INSTALLED_APPS = [\n            'django.contrib.auth',\n            'django.contrib.contenttypes',\n            'tpkg.app',\n        ]\n        SECRET_KEY = 'foobar'\n\n        MIDDLEWARE_CLASSES = (\n            'django.contrib.sessions.middleware.SessionMiddleware',\n            'django.middleware.common.CommonMiddleware',\n            'django.middleware.csrf.CsrfViewMiddleware',\n            'django.contrib.auth.middleware.AuthenticationMiddleware',\n            'django.contrib.messages.middleware.MessageMiddleware',\n        )\n\n        TEMPLATES = [\n            {\n                'BACKEND': 'django.template.backends.django.DjangoTemplates',\n                'DIRS': [],\n                'APP_DIRS': True,\n                'OPTIONS': {},\n            },\n        ]\n\n        %(extra_settings)s\n    ") % {
        'db_settings': repr(db_settings),
        'extra_settings': dedent(options['extra_settings']),
    })
    if options['project_root']:
        project_root = testdir.mkdir(options['project_root'])
    else:
        project_root = testdir.tmpdir
    tpkg_path = project_root.mkdir('tpkg')
    if options['create_manage_py']:
        project_root.ensure('manage.py')
    tpkg_path.ensure('__init__.py')
    app_source = REPOSITORY_ROOT.dirpath('pytest_django_test/app')
    test_app_path = tpkg_path.join('app')
    shutil.copytree(py.builtin._totext(app_source), py.builtin._totext(test_app_path))
    tpkg_path.join('the_settings.py').write(test_settings)
    monkeypatch.setenv('DJANGO_SETTINGS_MODULE', 'tpkg.the_settings')

    def create_test_module(test_code, filename='test_the_test.py'):
        r = tpkg_path.join(filename)
        r.write(dedent(test_code), ensure=True)
        return r

    def create_app_file(code, filename):
        r = test_app_path.join(filename)
        r.write(dedent(code), ensure=True)
        return r
    testdir.create_test_module = create_test_module
    testdir.create_app_file = create_app_file
    testdir.project_root = project_root
    return testdir

dataset/ETHPy150Open pytest-dev/pytest-django/tests/conftest.py django_testdir/original