Skip to content

Instantly share code, notes, and snippets.

@mneil
Created November 24, 2020 21:28
Show Gist options
  • Select an option

  • Save mneil/584c151c3ae239c565513f0a87c40c2b to your computer and use it in GitHub Desktop.

Select an option

Save mneil/584c151c3ae239c565513f0a87c40c2b to your computer and use it in GitHub Desktop.

Revisions

  1. mneil created this gist Nov 24, 2020.
    25 changes: 25 additions & 0 deletions conftest.py
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,25 @@

    '''
    Unit test setup automatically called
    '''
    from unittest import mock
    import pytest

    # Fixture, autouse
    @pytest.fixture(scope='session', autouse=True)
    def patch_boto3(request):
    '''patch things for every unit test'''
    # Patch boto client to return a magic mock by default during
    # Avoids ever making real calls in tests or getting botocore
    # credentials errors in tests
    patched = mock.patch('botocore.client.BaseClient._make_api_call')
    # Start the patch
    patched.start()
    def unpatch():
    '''try to unpatch if the patch is still active'''
    try:
    patched.stop()
    except IndexError:
    pass
    # When the test is over, run this method
    request.addfinalizer(unpatch)