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

Where reasonable, convert tests to free functions #993

Open
gadomski opened this issue Feb 15, 2023 · 2 comments
Open

Where reasonable, convert tests to free functions #993

gadomski opened this issue Feb 15, 2023 · 2 comments
Milestone

Comments

@gadomski
Copy link
Member

We switched to pytest in #939, which means we don't have to use unittest.TestCase anymore; we can switch to free functions. In most cases, converting tests should be as simple as changing:

class MyTestCase(unittest.TestCase):
    def test_foo(self) -> None:
        self.assertTrue(True)

to

def test_foo() -> None:
    assert True

While this is a little bike-sheddy, this does have some benefits:

  • Enable fixtures, parameterization, and custom hooks
  • Reduces confusion for new contributors, who might be unsure of which test format to use
  • Reduces the indentation level (a little thing, I know, but IMO it reads cleaner to have less leading whitespace)
github-merge-queue bot pushed a commit that referenced this issue Oct 16, 2023
* refactor: normalize import style

#1259

* refactor(tests): modernize version extension tests

- #993
- #948

* feat: add experimental to version ext

* feat: version is optional in version extension

* refactor: test import naming, ext

* feat: catalog extensions

* refactor: import style

* feat: add history media type

* feat: separate BaseVersionExtension

* feat: impl migration

* doc: fixups

* chore: update changelog

* fix(tests): mark some extra vcrs

* fix: pop_if_none on deprecated
@gadomski gadomski added this to the v2.0 milestone Sep 23, 2024
@teks
Copy link
Contributor

teks commented Jan 28, 2025

This seems straightforward so I'll make an attempt. 28 files have import unittest so I may split it into a few PRs so they don't get too long.

However, please let me know if there's a body of tests I should leave alone until some other work is done.

@gadomski
Copy link
Member Author

Nope, go to town 😄

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants