Skip to content

Unit Test Cleanup #368

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

Merged
merged 4 commits into from
Aug 2, 2022
Merged

Unit Test Cleanup #368

merged 4 commits into from
Aug 2, 2022

Conversation

pankajastro
Copy link
Contributor

@pankajastro pankajastro commented May 20, 2022

This is an attempt to improve the unit test case this PR will add the below value

  • We have to not write context` fixture in each test file
  • We can move mocked third-party API response that we want to test out of test case files
  • We can reuse the create_context method which is currently redundant at dozen of place
  • We can move the constant like conn_name, poll_interval and other repeated param out of the test file and reuse it
  • test cases name will be smaller that would be easy to read
  • It would be easy to read the case since now it will have a nice grouping which mapped to the actual class
  • It would be easy to add a new test case and improve/change the existing test case since it would be grouped in a class
  • Running of test would be easier using pytest I can run a group of tests as well as individual test

Since this PR have only changes for core providers so above points are currently applicable on core provider only

Closes: #294
Related to: #568

@pankajastro pankajastro linked an issue May 20, 2022 that may be closed by this pull request
@pankajastro pankajastro changed the title Unit test cleanup Unit Test Cleanup May 20, 2022
@codecov
Copy link

codecov bot commented May 20, 2022

Codecov Report

Merging #368 (e0f4dd0) into main (03d0bdc) will not change coverage.
The diff coverage is n/a.

@@           Coverage Diff           @@
##             main     #368   +/-   ##
=======================================
  Coverage   98.27%   98.27%           
=======================================
  Files          72       72           
  Lines        3996     3996           
=======================================
  Hits         3927     3927           
  Misses         69       69           

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 03d0bdc...e0f4dd0. Read the comment docs.

@pankajastro pankajastro requested a review from kaxil May 20, 2022 10:22
Copy link
Contributor

@bharanidharan14 bharanidharan14 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Need to test parametrize in class based approach

@kaxil kaxil changed the base branch from main to release-1.4 May 25, 2022 12:07
@kaxil kaxil changed the base branch from release-1.4 to main May 25, 2022 12:07
@pankajastro
Copy link
Contributor Author

pankajastro commented Jun 16, 2022

Need to test parametrize in class based approach

This shouldn't be a problem, I have checked in the apache repo

@pankajastro pankajastro marked this pull request as ready for review June 16, 2022 15:48
@kaxil kaxil requested a review from bharanidharan14 July 7, 2022 13:14
@kaxil
Copy link
Collaborator

kaxil commented Jul 7, 2022

What's the status of this PR?

@bharanidharan14
Copy link
Contributor

Need to test parametrize in class based approach

This should be a problem, I have checked in the apache repo

We can't have parametrize based function ?

@pankajastro
Copy link
Contributor Author

Need to test parametrize in class based approach

This should be a problem, I have checked in the apache repo

We can't have parametrize based function ?

It is doable, it's a typo in the last comment, updated it. https://github.com/apache/airflow/blob/main/tests/providers/amazon/aws/hooks/test_base_aws.py#L704

@pankajastro
Copy link
Contributor Author

pankajastro commented Jul 8, 2022

What's the status of this PR?

@kaxil This was one of my suggestions to improve unit test reusability and readability during our retro call. I came up with some improvements for one module core so that we can conclude that discussion.

Copy link
Contributor

@bharanidharan14 bharanidharan14 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Overall LGTM, only thing can you add more description what is done on the cleanup activity, so that it can be avoided in the upcoming PR

@bharanidharan14 bharanidharan14 self-requested a review July 12, 2022 05:49
@bharanidharan14
Copy link
Contributor

@pankajastro can you please fix the Description

@bharanidharan14
Copy link
Contributor

@pankajastro can we merge this ? Is anything need to be done ?

@pankajastro
Copy link
Contributor Author

@pankajastro can we merge this ? Is anything need to be done ?

I'm in favour of merging it but let me re-evaluate it and get back to you.

@pankajastro
Copy link
Contributor Author

@pankajastro can we merge this ? Is anything need to be done ?

Updated the description please let me know how this looks

@pankajastro
Copy link
Contributor Author

I want to merge this but before going ahead I would like to know what other people think about these changes. WDYT @phanikumv @kaxil @pankajkoti @bharanidharan14 @rajaths010494 ?

Copy link
Collaborator

@kaxil kaxil left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would like to hear opinions from others :)

Copy link
Collaborator

@pankajkoti pankajkoti left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The test coverage is dropping by 0.95% . Do we need to worry about it?

assert len(execution_dates) == 1

class TestExternalTaskSensorAsync:
TASK_ID = "external_task_sensor_check"
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

can we add this variables inside setup_class like class variables?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

do you mean I should create a setup class and keep this variable in that class? Can you please elaborate a little bit?

Copy link
Contributor

@bharanidharan14 bharanidharan14 Jul 27, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, you can do like this

class Test:
    def setup_class(self) -> None:
        self.xxxx: str = ""
        self.yyyyy: str = ''
        self.connection_string = (
        )

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

or you can create def test_init() inside the class

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

these variables are just single lines and getting used in this class only so moving outside to a different class not sure how much value will add. regarding variables like conn which might get used in multiple test classes, I'm planning to keep them in util

@pankajastro
Copy link
Contributor Author

pankajastro commented Jul 27, 2022

The test coverage is dropping by 0.95% . Do we need to worry about it?

If you see the delta changes #368 (comment) the coverage has dropped for most of the files which are not related to this PR so I don't think it matters much we still have all tests old test here

@pankajastro
Copy link
Contributor Author

Created a follow-up ticket #568

@pankajastro pankajastro merged commit 261f1f5 into main Aug 2, 2022
@pankajastro pankajastro deleted the unit_test_cleanup branch August 2, 2022 14:38
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[POC] Improve unit test quality
4 participants