Re: adding a simulation mode

Discussion in 'Python' started by andrea crotti, Jul 12, 2012.

  1. 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..
     
    andrea crotti, Jul 12, 2012
    #1
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. andrea crotti

    adding a simulation mode

    andrea crotti, Jul 4, 2012, in forum: Python
    Replies:
    4
    Views:
    226
    Paul Rubin
    Jul 4, 2012
  2. Mike C. Fletcher

    Re: adding a simulation mode

    Mike C. Fletcher, Jul 4, 2012, in forum: Python
    Replies:
    0
    Views:
    179
    Mike C. Fletcher
    Jul 4, 2012
  3. Devin Jeanpierre

    Re: adding a simulation mode

    Devin Jeanpierre, Jul 4, 2012, in forum: Python
    Replies:
    0
    Views:
    199
    Devin Jeanpierre
    Jul 4, 2012
  4. Dieter Maurer

    Re: adding a simulation mode

    Dieter Maurer, Jul 5, 2012, in forum: Python
    Replies:
    0
    Views:
    181
    Dieter Maurer
    Jul 5, 2012
  5. andrea crotti

    Re: adding a simulation mode

    andrea crotti, Jul 5, 2012, in forum: Python
    Replies:
    0
    Views:
    172
    andrea crotti
    Jul 5, 2012
Loading...

Share This Page