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

Unit test stub autogenerator #74

Open
skrawcz opened this issue Feb 26, 2023 · 3 comments
Open

Unit test stub autogenerator #74

skrawcz opened this issue Feb 26, 2023 · 3 comments

Comments

@skrawcz
Copy link
Collaborator

skrawcz commented Feb 26, 2023

Is your feature request related to a problem? Please describe.
Writing unit tests can be slow because you need to create the unit test stubs to exercise the hamilton functionality you just wrote.

Describe the solution you'd like

  1. You write your hamilton python functions.
  2. You use a command line (e.g. hamilton create_tests MODULE_NAME.py) to create pytest style unit test stubs for all (or a subset) of the hamilton functions within that module.
  3. The command line should append to an existing test_MODULE_NAME.py file if it exists.
  4. The command line should skip functions that already have tests defined for them.

E.g. take a function like:

def spend_per_signup(spend: pd.Series, signups: pd.Series) -> pd.Series:
    """The cost per signup in relation to spend."""
    return spend / signups

and then in the unit test file create something like:

def test_spend_per_signup() -> pd.Series:
    spend: pd.Series = pd.Series([]) # TODO: fill in
    signups: pd.Series = pd.Series([]) # TODO: fill in
    expected = pd.Series([]) # TODO: fill in
    actual = module_name.spend_per_signup(spend, signups)
    # because we're comparing pandas we should use the pandas testing module
    pd.testing.assert_series_equal(actual, expected)
    # if it wasn't comparing pandas we'd instead do
    assert actual == expected

Describe alternatives you've considered
Doing this manually.

Additional context
Most people don't like writing unit tests. We can at least speed up the process with such a tool.

@skrawcz
Copy link
Collaborator Author

skrawcz commented Feb 26, 2023

cc @CharityKithaka

@CharityKithaka
Copy link
Contributor

Noted thank you.

@skrawcz
Copy link
Collaborator Author

skrawcz commented Apr 16, 2024

@swapdewalkar want to comment so I can assign it please? :)

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

No branches or pull requests

2 participants