Git Product home page Git Product logo

Comments (10)

simonw avatar simonw commented on August 19, 2024

I'm tempted to write these tests in bash, so they exercise the actual s3-credentials command itself.

from s3-credentials.

simonw avatar simonw commented on August 19, 2024

Adapting this pattern: https://stackoverflow.com/a/61193490/6083

This in conftest.py:

import pytest


def pytest_addoption(parser):
    parser.addoption(
        "--integration", action="store_true", default=False, help="run integration tests"
    )


def pytest_collection_modifyitems(config, items):
    if config.getoption("--integration"):
        # Also run integration tests
        return
    skip_slow = pytest.mark.skip(reason="use --integration option to run")
    for item in items:
        if "integration" in item.keywords:
            item.add_marker(skip_slow)

Then mark integration tests like so:

@pytest.mark.integration
def test_integration():
    assert False, "Failing integration test"

Running pytest skips them, running pytest --integration executes them.

from s3-credentials.

simonw avatar simonw commented on August 19, 2024

In tests/test_integration.py I can use this to skip having to add that decorator to every test function:

import pytest

# Mark all tests in this module with "integration":
pytestmark = pytest.mark.integration


def test_integration():
    assert False, "Failing integration test"

from s3-credentials.

simonw avatar simonw commented on August 19, 2024

The one thing I won't be able to test automatically: that tokens with --duration 15m expire (see #duration) - because 15m is the minimum duration allowed by STS and I don't want to have the tests hang for 15 minutes waiting for that to happen.

from s3-credentials.

simonw avatar simonw commented on August 19, 2024

.... unless i have a pytest --integration-long option which executes those tests and means that the test suite will take 15 minutes to run!

from s3-credentials.

simonw avatar simonw commented on August 19, 2024

This is another reason to add s3-credentials list-bucket in #28 - so I can use it as part of these tests.

from s3-credentials.

simonw avatar simonw commented on August 19, 2024

Actually no, I don't need list-bucket - I can use boto3 directly to confirm that things have happened.

from s3-credentials.

simonw avatar simonw commented on August 19, 2024

This was really annoying: I kept getting errors that the access key I was trying to use for the put_object didn't exist.

I tried sleeping for 10 seconds and it started working. I tried sleeping for 5 seconds and it failed again. So 10 seconds it is.

# Bucket should exist - found I needed to sleep(10) before put-object would work
time.sleep(10)
assert bucket_exists(s3, bucket_name)
# Use the credentials to write a file to that bucket
credentials_s3.put_object(
Body="hello".encode("utf-8"), Bucket=bucket_name, Key="hello.txt"
)

from s3-credentials.

simonw avatar simonw commented on August 19, 2024

I only have a test for the happy path right now, but I'll add more tests to this module as part of the work on time limited credentials in #27.

from s3-credentials.

simonw avatar simonw commented on August 19, 2024

pytest --integration documentation: https://github.com/simonw/s3-credentials/blob/f70e76c37b638492b128d3781016166c7da88806/README.md#integration-tests

from s3-credentials.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.