-
Notifications
You must be signed in to change notification settings - Fork 16.4k
Migrate amazon provider hooks tests from unittests to pytest
#28039
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
Migrate amazon provider hooks tests from unittests to pytest
#28039
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.
This simple change actually speedup test execution from 30 sec to 2 seconds
before
============================ slowest 100 durations =============================
30.03s call tests/providers/amazon/aws/hooks/test_emr_containers.py::TestEmrContainerHook::test_query_status_polling_with_timeout
after
2.01s call tests/providers/amazon/aws/hooks/test_emr_containers.py::TestEmrContainerHook::test_query_status_polling_with_timeout
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.
nice, but do we need to wait at all ? is poll_interval = 0 an option ?
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.
Actually we do not need to wait at all but better to use freezegun or mock time.sleep however with poll_interval = 0 it would be run just 0.5 sec (localy).
But also it shows that there is no validation for this value. Usual 0 for any wait interval in general not a good idea,
because it could easily converted to something like
while True:
pass # 100% core 😢 usageOr in this case just exceed the limits of AWS API
|
That's awesome. I was literally looking at this earlier this week and have some local code where I started working on it. 👍 Will review ASAP |
ferruzzi
left a comment
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.
Looks great, thanks!
(non-binding approval)
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.
Do we want to remove the given/when/then comments in the very few places they still exist while we're at it? If you don't want to mess with that now, that's understandable too.
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.
Right now main target just migrate to pytests.
It is good point to change something from the past 😉
To be honest a lot of test need to rewrite later anyway
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.
Yeah, every time I try do add some new code I find a dozen older bits I'd love to redo in the process. Like why are we mocking get_conn in every test instead of making one fixture to do it? I'll take care of that one at some point. Can't fix it all at once 👍
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 change requested/required, just chatter) I mentioned on slack that I had started on some of these; this was the rabbit hole that got me there... I started updating any hooks that still used get_conn() instead of the conn cached property, which led to updating the mocked values in the unit tests, which led to converting them all to pytest which... never got finished :P So again, thanks for taking this on!
vincbeck
left a comment
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.
Love to see this clean up!
vandonr-amz
left a comment
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.
nice.
I noticed that on some setup_methods you added the optional method parameter without using it, while you skipped it on others. I think it'd be best to omit it wherever possible (i.e. probably everywhere in this case)
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.
nice, but do we need to wait at all ? is poll_interval = 0 an option ?
That's funny but if |
Ah yes I imagine because of the order of arguments, but I imagine in test_datasync it's not needed ? and nit: I like using |
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.
Original @vandonr-amz
Ah yes I imagine because of the order of arguments, but I imagine in test_datasync it's not needed ?
Actually this arg needed because we decorated entire class
test setup failed
args = (<tests.providers.amazon.aws.hooks.test_datasync.TestDataSyncHookMocked object at 0x109fdf4c0>, <bound method TestData...HookMocked.test_init of <tests.providers.amazon.aws.hooks.test_datasync.TestDataSyncHookMocked object at 0x109fdf4c0>>)
kwargs = {}
def wrapper(*args, **kwargs):
self.start(reset=reset)
try:
> result = func(*args, **kwargs)
E TypeError: setup_method() takes 1 positional argument but 2 were given
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.
Is it also needed for mocks that "generate" no arguments, like the @mock.patch.dict ?
And even with this case we need 2 arguments
args = (<tests.providers.amazon.aws.hooks.test_batch_client.TestBatchClientDelays object at 0x1071f0f70>, <bound method TestB...tDelays.test_init of <tests.providers.amazon.aws.hooks.test_batch_client.TestBatchClientDelays object at 0x1071f0f70>>)
kw = {}
@wraps(f)
def _inner(*args, **kw):
self._patch_dict()
try:
> return f(*args, **kw)
E TypeError: setup_method() takes 1 positional argument but 2 were given
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.
Right now main target just migrate to pytests.
It is good point to change something from the past 😉
To be honest a lot of test need to rewrite later anyway
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.
Original @vandonr-amz
and nit: I like using _ as name for the arguments that are unused, it's a clear way to mark them as "only here for the compiler to be happy"
This mostly as reminder what the actual argument here.
vandonr-amz
left a comment
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.
interesting how arguments work with mocks in setup...
Thank you for double-checking.
ferruzzi
left a comment
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.
Thanks for the explanation on the method fixture, that was somewhat confusing. I think the rest of my thoughts were addressed, non-binding approval pending the other folks are cool with their comments.
a2c1503 to
c4201d9
Compare
…28145) Related: #28039 #28139 Migrate Amazon provider's transfer tests to `pytest`. All changes are more or less straightforward: - Get rid of unittests.TestCase class and TestCase.assert* methods - Convert setUp* and tearDown* methods to appropriate pytest alternative - Replace decorator `parameterized.expand` by `pytest.mark.parametrize`. - Renamed `@patch` to `@mock.patch` to conform to other tests
related: #27970
Migrate Amazon provider's hooks and utils tests to
pytest.All changes are more or less straightforward:
unittests.TestCaseclass and TestCase.assert* methodsparameterized.expandbypytest.mark.parametrize.See additional findings, info about significant changes and potential follow up in comments