garnaat / placebo

Make boto3 calls that look real but have no effect.
Apache License 2.0
394 stars 28 forks source link

using placebo_session #54

Closed markfink closed 8 years ago

markfink commented 8 years ago

new to placebo so this is most likely my fault. Any idea how to fix this?

___________________________________________________________ test_list_stacks ____________________________________________________________

args = (), kwargs = {}, session_kwargs = {'profile_name': 'superuser-dev', 'region_name': 'eu-west-1'}
profile_name = 'superuser-dev', session = Session(region='eu-west-1')

    @functools.wraps(function)
    def wrapper(*args, **kwargs):
        session_kwargs = {
            'region_name': os.environ.get('AWS_DEFAULT_REGION', 'us-east-1')
        }
        profile_name = os.environ.get('PLACEBO_PROFILE', None)
        if profile_name:
            session_kwargs['profile_name'] = profile_name

        session = boto3.Session(**session_kwargs)

>       self = args[0]
E       IndexError: tuple index out of range

../venv/local/lib/python2.7/site-packages/placebo/utils.py:29: IndexError
======================================================= 1 failed in 0.73 seconds ========================================================

this is my simple testcase:

from placebo.utils import placebo_session
...

@pytest.mark.aws
@check_preconditions
@placebo_session
def test_list_stacks(session):
    out = StringIO()
    list_stacks(session, out=out)
    assert_regexp_matches(out.getvalue().strip(), 'listed \d+ stacks')

I am using placebo in record mode like in the docu:

$ PLACEBO_PROFILE=superuser-dp-dev PLACEBO_MODE=record python -m pytest tests/test_aws.py::test_list_stacks
markfink commented 8 years ago

my problem was related to how I invoke the test using pytest. I found a solution... just want to document it in case sb runs into it. Instead of using @placebo_session I wrote a pytest fixture (uses PLACEBO_MODE env variable, too):

@pytest.fixture(scope='module')  # 'function' or 'module'
def boto_session():
    session = boto3.session.Session()
    pill = placebo.attach(session, data_path=here('./resources/placebo'))
    if os.getenv('PLACEBO_MODE').lower() == 'record':
        pill.record()
    else:
        pill.playback()
    yield session
webratz commented 6 years ago

I stumbled upon the same thing. I tried to run it with your fixture, but I'm still getting the same error message as you did