Skip to content
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

Replace unittest with pytest in cli tests and document endstate #874

Merged
merged 10 commits into from
Feb 9, 2022

Conversation

cidrblock
Copy link
Collaborator

This is follow on work from #872 which guarded against the use of unittest.

  • Made minimal changes necessary to switch to pytest-mock from unittest-mock
  • Updated docstrings as encountered
  • Relevant docstrings exceptions removed from flake8 config for candidate linters pydocstyle and darglint
  • Added pytest-mock as a dependency

@cidrblock cidrblock requested review from a team, relrod, ganeshrn and priyamsahoo February 5, 2022 13:23
@cidrblock cidrblock enabled auto-merge (squash) February 5, 2022 13:34
@cidrblock cidrblock added the tests Related to testing and CI label Feb 5, 2022
Co-authored-by: Sviatoslav Sydorenko <wk.cvs.github@sydorenko.org.ua>
Copy link
Member

@webknjaz webknjaz left a comment

Choose a reason for hiding this comment

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

I don't seem to see any of the updated places needing mocker at all. Everything can be implemented with the built-in monkeypatch.setattr() and monkeypatch.setenv().

@cidrblock cidrblock disabled auto-merge February 5, 2022 14:00
@cidrblock
Copy link
Collaborator Author

I don't seem to see any of the updated places needing mocker at all. Everything can be implemented with the built-in monkeypatch.setattr() and monkeypatch.setenv().

I was hoping you might bring attention to this.

In #872 , we suggest the use of "unittest.mock:pytest-mock" and I suggested others help clean these up. Today, I thought, If I'm asking someone else to do this, I should t least fix a few myself.

Based on the #872 I went directly for pytest-mock as a replacement, which I believe others may have done as well.

I think this finding might merit documentation somewhere, that we prefer the use of monkeypatch over pytest-mock where it can be used, which I should have suggested in #872 but didn't think of it at the time.

I will add an issue related to that so it can be added to the upcoming developer guide when it arrives.

I will also make the changes, because I agree, no need to pull in pytest-mock until it is needed.

@webknjaz
Copy link
Member

webknjaz commented Feb 5, 2022

I will also make the changes, because I agree, no need to pull in pytest-mock until it is needed.

I think it may be useful when replacing the decorators or needing to automatically and implicitly use magic mocks or spy on things. But none of the diff changes I see included right now use that.

@webknjaz
Copy link
Member

webknjaz commented Feb 5, 2022

I think this finding might merit documentation somewhere, that we prefer the use of monkeypatch over pytest-mock where it can be used, which I should have suggested in #872 but didn't think of it at the time.

Totally agreed. None of https://docs.pytest.org/en/latest/how-to/monkeypatch.html / https://pypi.org/p/pytest-mock have this comparison in their documentation.

Having some sort of dos and don'ts could be useful.

@cidrblock cidrblock changed the title Switch to pytest-mock in several tests Switch to pytest-mock in several tests; adding, correcting docstrings to help reviewers better understand what each function and file touched does. Feb 5, 2022
@cidrblock cidrblock changed the title Switch to pytest-mock in several tests; adding, correcting docstrings to help reviewers better understand what each function and file touched does. Remove unittest.mock in several tests; adding, correcting docstrings to help reviewers better understand what each function and file touched does. Feb 5, 2022
@cidrblock cidrblock changed the title Remove unittest.mock in several tests; adding, correcting docstrings to help reviewers better understand what each function and file touched does. Switch from unittest.mock to pytests in several tests; adding, correcting docstrings to help reviewers better understand what each function and file touched does. Feb 5, 2022
Copy link
Member

@ssbarnea ssbarnea left a comment

Choose a reason for hiding this comment

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

Please try to follow the famous 72/50 rule, that PR title spreading on 3 lines in browser is not easy to read, on git log would even be worse.

From personal experience be sure that the editor you use to write commit message is able to display 72/50 markers, as this helps. I use Fork.app on macos, but also code is able to display guidelines for these.

@cidrblock cidrblock changed the title Switch from unittest.mock to pytests in several tests; adding, correcting docstrings to help reviewers better understand what each function and file touched does. Switch from unittest.mock to pytest in several tests; adding, correcting docstrings to help reviewers better understand what each function and file touched does. Feb 5, 2022
@webknjaz
Copy link
Member

webknjaz commented Feb 5, 2022

that PR title spreading on 3 lines in browser is not easy to read

+1 I've also made this screenshot to make the problem more visually accessible:
gh-long-pr-title

@cidrblock cidrblock changed the title Switch from unittest.mock to pytest in several tests; adding, correcting docstrings to help reviewers better understand what each function and file touched does. Replace unittest with pytest in gs h f Feb 5, 2022
@cidrblock cidrblock changed the title Replace unittest with pytest in gs h f Replace unittest with pytest in cli tests, documenting endstate Feb 5, 2022
@cidrblock cidrblock changed the title Replace unittest with pytest in cli tests, documenting endstate Replace unittest with pytest in cli tests and document endstate Feb 5, 2022
@cidrblock
Copy link
Collaborator Author

Good stuff here about that for me, since I have chosen to use vscode.... https://robertcooper.me/post/git-commit-messages#using-vscode-to-write-commit-messages

@webknjaz
Copy link
Member

webknjaz commented Feb 5, 2022

Good stuff here about that for me, since I have chosen to use vscode.... robertcooper.me/post/git-commit-messages#using-vscode-to-write-commit-messages

Yep, I know some people use set VS Code as their default Git editor. You may also like the possibility to configure a commit template — https://codeinthehole.com/tips/a-useful-template-for-commit-messages/.

P.S. Here's some inspiration on how to craft great commit messages: https://twitter.com/nedbat/status/1283147492616556544.

@webknjaz
Copy link
Member

webknjaz commented Feb 7, 2022

@cidrblock #896 this may be helpful to keep yourself in check. Note that it only checks the last commit. Try it out, though.

@cidrblock
Copy link
Collaborator Author

@webknjaz @ssbarnea anything else here? I've got other changes to make to the same files and would love to avoid the conflict resolution.

@ssbarnea
Copy link
Member

ssbarnea commented Feb 9, 2022

Approved but I will take the opportunity to mention that I have mixed feelings about thin kind of move. I remember people on openstack being actively opposed to pytest being a walled garden for testing and use of its own implementation limiting the options.

Is not really a problem for us as we use only pytest everywhere, but I would avoid bothering about switching stuff unless they are broken. If it still works with older approach, why bother? (no need to answer).

@cidrblock
Copy link
Collaborator Author

Approved but I will take the opportunity to mention that I have mixed feelings about thin kind of move. I remember people on openstack being actively opposed to pytest being a walled garden for testing and use of its own implementation limiting the options.

Is not really a problem for us as we use only pytest everywhere, but I would avoid bothering about switching stuff unless they are broken. If it still works with older approach, why bother? (no need to answer).

No need, but I am compelled.

I want to explain how this played out, so future contributors don't get put in a similar situation.

Because many developers look at the current code base to reuse pieces of code when adding to it, I wanted to make sure these got converted to pytest tests so they can serve as valid examples in the future.

I also wanted the experience of doing the conversion and the learning about pytest that came with it.

When mixed messages from 2 repository owners fall on the shoulders of a contributor to sort out and weigh, they might find it frustrating and be led to believe the team does not have one voice.

Please help me make sure this doesn't happen again, let's all try to stay in sync better, including me with both of you.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
tests Related to testing and CI
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants