Skip to content
This repository was archived by the owner on Mar 2, 2026. It is now read-only.

testing: use pytest idioms for unit tests#499

Merged
tseaver merged 38 commits intomainfrom
498-use_pytest_idioms_for_unit_tests
Dec 21, 2021
Merged

testing: use pytest idioms for unit tests#499
tseaver merged 38 commits intomainfrom
498-use_pytest_idioms_for_unit_tests

Conversation

@tseaver
Copy link
Copy Markdown
Contributor

@tseaver tseaver commented Nov 30, 2021

Closes #498.

@tseaver tseaver requested review from kolea2, plamut and tswast November 30, 2021 19:10
@tseaver tseaver requested a review from a team as a code owner November 30, 2021 19:10
@product-auto-label product-auto-label bot added the api: firestore Issues related to the googleapis/python-firestore API. label Nov 30, 2021
@google-cla google-cla bot added the cla: yes This human has signed the Contributor License Agreement. label Nov 30, 2021
@tseaver
Copy link
Copy Markdown
Contributor Author

tseaver commented Nov 30, 2021

Reviewers: this is a big PR, and mostly involves repetition of the same few transforms:

  • Use normal assert rather than self.assert*.
  • Replace self.assertRaises with pytest.raises.
  • Convert testcase helper methods to module-scope functions.
  • Drop use of the unittest.TestCase base class, converting testcase methods to module-scope functions.
  • Minor cleanups of module-scope imports.

@tswast
Copy link
Copy Markdown
Contributor

tswast commented Dec 6, 2021

Thanks! I like this refactoring. It'll take me some time to get through this review, though. I'll set some time aside this week for it.

@tseaver tseaver added the do not merge Indicates a pull request not ready for merge, due to either quality or timing. label Dec 6, 2021
@tseaver tseaver self-assigned this Dec 6, 2021
@tseaver
Copy link
Copy Markdown
Contributor Author

tseaver commented Dec 6, 2021

4ff4506 seems to have broken Watch.on_snapshot -- I will check it out tomorrow.

All the earlier "test refactoring" commits should be reviewable as it.

@tseaver tseaver force-pushed the 498-use_pytest_idioms_for_unit_tests branch from 10eb32f to 9027cc7 Compare December 7, 2021 15:54
@tseaver
Copy link
Copy Markdown
Contributor Author

tseaver commented Dec 7, 2021

I've rebased the branch to remove the last two commits (4ff4506 and 10eb32f), leaving this PR as purely unit-test refactoring.

@tseaver tseaver removed the do not merge Indicates a pull request not ready for merge, due to either quality or timing. label Dec 7, 2021
Copy link
Copy Markdown
Contributor

@tswast tswast left a comment

Choose a reason for hiding this comment

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

A few minor issues, but otherwise LGTM

Comment on lines +83 to +87
def test__numericvalue_ctor_w_int():
values = (-10, -1, 0, 1, 10)
for value in values:
inst = _make_numeric_value(value)
assert inst.value == value
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Suggested change
def test__numericvalue_ctor_w_int():
values = (-10, -1, 0, 1, 10)
for value in values:
inst = _make_numeric_value(value)
assert inst.value == value
@pytest.mark.parametrize(["value"], [(-10,), (-1,), (0,), (1,), (10,)])
def test__numericvalue_ctor_w_int(value):
inst = _make_numeric_value(value)
assert inst.value == value

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

@tseaver tseaver requested a review from tswast December 9, 2021 15:05
@tseaver tseaver merged commit c4878c3 into main Dec 21, 2021
@tseaver tseaver deleted the 498-use_pytest_idioms_for_unit_tests branch December 21, 2021 18:42
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

api: firestore Issues related to the googleapis/python-firestore API. cla: yes This human has signed the Contributor License Agreement.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Refactor unit tests to use py.test idioms

2 participants