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

Use plain asserts and pytest-mock in tests/unit/test_backend.py #116

Merged
merged 4 commits into from
Oct 24, 2024

Conversation

cognifloyd
Copy link
Member

@cognifloyd cognifloyd commented Oct 23, 2024

In #115, I need to add tests, and the cleanest way to do that is with parametrization. But:

  • Parametrization is incompatible with unittest-style tests.
  • Parametrization also doesn't play nicely with @mock.patch.object decorators.

So, this switches:

  • from unittest.TestCase with unittest asserts, to simple test functions with plain asserts.
  • from mock to pytest-mock (a nice wrapper around unittest.mock for pytest-style fixtures)

This PR only refactors tests/unit/test_backend.py, not any of the other test files.
(Contributions welcome to migrate the other tests.)

In order to review this PR, please review each commit separately. For the first commit make sure to "hide whitespace":
(see https://github.blog/news-insights/product-news/ignore-white-space-in-code-review/ for instructions on hiding whitespace changes).

Parametrization is incompatible with unittest-style tests.
So, this migrates test_backend to use plain asserts instead.
@cognifloyd cognifloyd requested review from nzlosh, guzzijones and a team October 23, 2024 17:04
@cognifloyd cognifloyd self-assigned this Oct 23, 2024
@cognifloyd cognifloyd changed the title Use plain asserts in tests/unit/test_backend.py Use plain asserts and pytest-mock in tests/unit/test_backend.py Oct 23, 2024
@cognifloyd cognifloyd force-pushed the pytest-conversion branch 3 times, most recently from 988f1ce to 958e162 Compare October 23, 2024 19:45
Parametrization also doesn't play nicely with @mock.patch.object decorators,
so this refactor paves the way for additional parametrization in future PRs.
@cognifloyd cognifloyd merged commit fd9a095 into master Oct 24, 2024
7 checks passed
@cognifloyd cognifloyd deleted the pytest-conversion branch October 24, 2024 13:48
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants