Skip to content

Mocking sys.argv and sys.stdout like in patch #24

@relte

Description

@relte

Is it possible to use Mockito to replace sys.argv or sys.stdout?

I could do it with unittest.mock.patch but I'd rather use a single mocking tool:

def it_outputs_answers_based_on_an_argument(when):
    with patch('sys.argv', ['cli.py', 'all']):
        when('app.cli.ApiClient').search_answers('all').thenReturn([
            {
                'id': 1,
                'question': 'A?',
                'content': 'B'
            }
        ])

        with patch('sys.stdout', StringIO()) as stdout:
            main()
            output = stdout.getvalue().strip()
            expect(output).to(equal('A?\n--\nB'))

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions