Alternatives to pytest-watch on python unit test with pytest

24 views Asked by At

I have been trying to watch my tests WITH test coverage without much of a success. My best attempt sofar is to install packaeges pip install pytest pytest-watch pytest-cov and run on separate terminals or tabs these commands, below

  1. Watch tests: ptw --quiet --spool 200 --clear --nobeep --config pytest.ini --ext=.py --onfail="echo Tests failed, fix the issues" -v

  2. Coverage: coverage run --rcfile=.coveragerc -m pytest && coverage report --omit="tests/*,src/main.py,*/__init__.py,*/constants.py" --show-missing

An alternative to this approach is the shell script below. To run it, run command: chmod +x watch.sh && ./watch

#!/bin/bash
clear

while true; do
  coverage run --rcfile=.coveragerc -m pytest
  coverage report --omit="tests/*,src/main.py,*/__init__.py,*/constants.py" --show-missing
  
  sleep 5  # Adjust delay between test runs if needed
  clear
done

It renders slower compared to command run ptw, but outputs exactly what I want. Would you please, provide maybe more effective alternatives than mine?

Thanks. :)

0

There are 0 answers