Skip to content

hasankanaan26/Unit-Testing-Python

Repository files navigation

Testing for Beginners

A hands-on introduction to testing Python code, written for people who've coded a bit but have never written a test. Five short lessons that build on each other — by the end you'll know what tests are, why they're worth your time, and how to write them with pytest.

How to use this

  1. Clone or download this repo.
  2. Install pytest:
    pip install -r requirements.txt
    
  3. Work through the folders in order. Each folder has a README.md that explains the concept, plus example code and tests you can run.
  4. From inside any lesson folder, run:
    pytest
    

That's it. Don't skip ahead — each lesson assumes you've done the previous one.

Or use Docker

If you'd rather not install anything locally:

docker build -t testing-for-beginners .
docker run --rm testing-for-beginners                  # run all tests
docker run --rm testing-for-beginners pytest 02-pytest-basics  # run one lesson
docker run --rm -it testing-for-beginners bash         # poke around

The lessons

  1. 01-why-test — What tests are and why they matter, shown by catching a real bug.
  2. 02-pytest-basics — How pytest finds and runs tests, and how assert works.
  3. 03-fixtures — How to share setup code between tests without repeating yourself.
  4. 04-mocking — How to test code that talks to APIs or other external things.
  5. 05-what-to-test — Practical guidance on what's actually worth testing.
  6. 06-testing-agents — Bonus lesson: unit testing LangGraph agents with a fake LLM.

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors