-
Notifications
You must be signed in to change notification settings - Fork 0
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Use DI & Upgrade Pytest #4
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Context
@@ -11,7 +11,7 @@ mock = "^4.0.3" | |||
pre-commit = "^2.17.0" | |||
|
|||
[tool.poetry.dev-dependencies] | |||
pytest = "^5.2" | |||
pytest = "^6.2.5" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
class S3Util: | ||
def __init__(self): | ||
self.s3_client = boto3.client("s3") | ||
def __init__(self, s3_client): |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
DI: Inject dependencies in constructor for testability
|
||
|
||
@patch("python_poetry_template.s3_util_class.boto3") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
No longer have to patch. Can create the mock directly and pass it in when instantiating the class.
mock_boto3.client.return_value = client_mock | ||
# Mock the s3_client with a return value on chained method calls | ||
mock_s3_client = MagicMock() | ||
mock_s3_client.get_paginator().paginate().build_full_result.return_value = {"Contents": []} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Simplifying the chaining call instead of creating 3 different mocks & their individual responses.
pytest-dev/pytest#8540