@pytest.yield_fixture
def dir_with_hooks(tmpdir):
 hooks_dir = tmpdir.mkdir('hooks')
 pre_hook_content = textwrap.dedent(u"\n        #!/usr/bin/env python\n        # -*- coding: utf-8 -*-\n        print('pre_gen_project.py~')\n        ")
 pre_gen_hook_file = (hooks_dir / 'pre_gen_project.py~')
 pre_gen_hook_file.write_text(pre_hook_content, encoding='utf8')
 post_hook_content = textwrap.dedent(u"\n        #!/usr/bin/env python\n        # -*- coding: utf-8 -*-\n        print('post_gen_project.py~')\n        ")
 post_gen_hook_file = (hooks_dir / 'post_gen_project.py~')
 post_gen_hook_file.write_text(post_hook_content, encoding='utf8')
 (yield str(tmpdir))
 pre_gen_hook_file.remove()
 post_gen_hook_file.remove()

@ pytest . yield_fixture def dir_with_hooks ( tmpdir ) : hooks_dir = tmpdir . mkdir ( 'hooks' ) pre_hook_content = textwrap . dedent ( u"\n        #!/usr/bin/env python\n        # -*- coding: utf-8 -*-\n        print('pre_gen_project.py~')\n        " ) pre_gen_hook_file = ( hooks_dir / 'pre_gen_project.py~' ) pre_gen_hook_file . write_text ( pre_hook_content , encoding = 'utf8' ) post_hook_content = textwrap . dedent ( u"\n        #!/usr/bin/env python\n        # -*- coding: utf-8 -*-\n        print('post_gen_project.py~')\n        " ) post_gen_hook_file = ( hooks_dir / 'post_gen_project.py~' ) post_gen_hook_file . write_text ( post_hook_content , encoding = 'utf8' ) ( yield str ( tmpdir ) ) pre_gen_hook_file . remove ( ) post_gen_hook_file . remove ( )
yield a directory that contains hook backup files .