Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.python > #25217
| References | <CAF_E5JbFK4ZYsvwdVHxw-S7vLkpwskF=OCohWW2okmPi56ObOA@mail.gmail.com> <87liiyr48f.fsf@handshake.de> <CAF_E5JaUD-AyudMut00Bjjan0Zv767do=XM_zKS3DvBmC4reyQ@mail.gmail.com> <CAF_E5JYDXe_tni4NohVE5Mj8bEjeJ7xxZ6XLDhaM6sQi_oX0aA@mail.gmail.com> |
|---|---|
| Date | 2012-07-12 14:55 +0100 |
| Subject | Re: adding a simulation mode |
| From | andrea crotti <andrea.crotti.0@gmail.com> |
| Newsgroups | comp.lang.python |
| Message-ID | <mailman.2041.1342101337.4697.python-list@python.org> (permalink) |
One way instead that might actually work is this
def default_mock_action(func_name):
def _default_mock_action(*args, **kwargs):
print("running {} with args {} and {}".format(func_name, args, kwargs))
return _default_mock_action
def mock_fs_actions(to_run):
"""Take a function to run, and run it in an environment which
mocks all the possibly dangerous operations
"""
side_effect = [
'copytree',
'copy',
]
acts = dict((s, default_mock_action(s)) for s in side_effect)
with patch('pytest.runner.commands.ShellCommand.run',
default_mock_action('run')):
with patch.multiple('shutil', **acts):
to_run()
So I can just pass the main function inside the mock like
mock_fs_actions(main)
and it seems to do the job, but I have to list manually all the things
to mock and I'm not sure is the best idea anyway..
Back to comp.lang.python | Previous | Next | Find similar | Unroll thread
Re: adding a simulation mode andrea crotti <andrea.crotti.0@gmail.com> - 2012-07-12 14:55 +0100
csiph-web