Skip to content

Surya-SDE16/Python_TDD_Demo

 
 

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

5 Commits
 
 
 
 
 
 
 
 

Repository files navigation

Mini Pytest TDD

A tiny exercise to practice TDD with pytest using three features:

  • @pytest.mark.parametrize
  • pytest.raises
  • pytest.approx

You'll implement a few simple math functions working purely with basic float types, then run the tests and iterate until they pass.

What you will implement

Open src/simple_math/core.py and complete these functions (they currently raise NotImplementedError):

  • add(a: float, b: float) -> float: Return a + b.
  • safe_divide(a: float, b: float) -> float: Return a / b; raise ValueError if b == 0.0.
  • average(xs: list[float]) -> float: Return the arithmetic mean; raise ValueError for an empty list.

Each function includes a docstring with examples to guide you.


Setup & Run (Poetry only)

  1. From the project root, install dependencies:

    poetry install
  2. Run tests:

    poetry run pytest -q

TDD Workflow Tips

  1. Run tests first to see failures.
  2. Implement the smallest change to make one test pass.
  3. Re-run tests, refactor only after green.
  4. Repeat.

Happy testing! 🎯

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages

  • Python 100.0%