@bdd.when(bdd.parsers.parse('I set up a fake editor replacing "{text}" by "{replacement}"'))
def set_up_editor_replacement(quteproc, httpbin, tmpdir, text, replacement):
 text = text.replace('(port)', str(httpbin.port))
 script = (tmpdir / 'script.py')
 script.write(textwrap.dedent('\n        import sys\n\n        with open(sys.argv[1], encoding=\'utf-8\') as f:\n            data = f.read()\n\n        data = data.replace("{text}", "{replacement}")\n\n        with open(sys.argv[1], \'w\', encoding=\'utf-8\') as f:\n            f.write(data)\n    '.format(text=text, replacement=replacement)))
 editor = '"{}" "{}" {{}}'.format(sys.executable, script)
 quteproc.set_setting('general', 'editor', editor)

@ bdd . when ( bdd . parsers . parse ( 'I set up a fake editor replacing "{text}" by "{replacement}"' ) ) def set_up_editor_replacement ( quteproc , httpbin , tmpdir , text , replacement ) : text = text . replace ( '(port)' , str ( httpbin . port ) ) script = ( tmpdir / 'script.py' ) script . write ( textwrap . dedent ( '\n        import sys\n\n        with open(sys.argv[1], encoding=\'utf-8\') as f:\n            data = f.read()\n\n        data = data.replace("{text}", "{replacement}")\n\n        with open(sys.argv[1], \'w\', encoding=\'utf-8\') as f:\n            f.write(data)\n    ' . format ( text = text , replacement = replacement ) ) ) editor = '"{}" "{}" {{}}' . format ( sys . executable , script ) quteproc . set_setting ( 'general' , 'editor' , editor )
set up general->editor to a small python script doing a replacement .