DEV Community

kkrishnan10
kkrishnan10

Posted on

Lab 7 - Testing with pytest

For Lab 7, I used pytest and pytest-cov in my repo ContextWeaver because they’re simple, popular, and well-documented tools for testing in Python. I added them to my requirements.txt, installed them in my virtual environment, and created a tests folder with a conftest.py file so my test files could import modules from src.

I started by writing unit tests for ignore.py to check how it handled default, gitignore, and extra patterns, then added integration tests for main.py to make sure the CLI worked correctly with different ignore options.

At first, one of my tests failed because of how my pattern matching worked, which helped me understand how *.py behaves in subdirectories. Running coverage showed that ignore.py had 100% coverage, while the overall project had 23%, so I could clearly see what still needed more testing.

I realized how much automated testing improves confidence in my code, especially for catching small mistakes early, and I will definitely keep using pytest for future projects.

Top comments (0)