Unit test stub autogenerator
- Dominant language
- Jupyter Notebook
- Stars
- 2.6k
- Forks
- 213
- PR merge metrics
- No merged PRs in 30d
Description
**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:
```python
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:
```python
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.
Contributor guide
Assessment
This issue has not been assessed yet.