Add unit test
Steps
- Find an existing test for a similar function. Match its style — class-based vs functional, parametrize vs loop, mocking style.
- Locate the test file. Conventions vary:
tests/test_foo.py,test_foo.pynext tofoo.py, orsrc/foo/_test.py. Don't invent a new one. - Test the public behavior, not implementation details. Edge cases first: empty input, boundary values, error paths.
- Avoid mocking yfinance / requests / DB clients by isolating logic from I/O — pass dataframes/dicts to pure functions and let the network boundary live in one place.
- Run only the new test first (
pytest -k test_<name>orpython -m unittest test_module.TestClass.test_method) to confirm it actually exercises the change. - Then run the full suite with
{{ profile.test_command if profile and profile.test_command else "the project test_command" }}.
Failure modes to avoid
- Adding pytest fixtures when the project uses plain unittest.
- Testing the test framework instead of the function ("assert test runner works").
- Mocking the world — if you're mocking 5 things to test one function, refactor.
- Writing tests that pass only with the implementation in front of you (write the test first if you can).