def create_test_environment(files): with create_tmp_dir() as dirname: GlobalConfig.clear_for_tests() for filename, contents in files.items(): with open(os.path.join(dirname, filename), 'w') as f: f.write(contents) yield dirname