Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is there a way to start unit tests which related only to changed code?

In my Python project, we have a big number of unit tests (some thousands). Though they are logically distributed between files and classes, I need sometimes a lot of time in order to find ones, which cover the functionality I'm changing.

Of course, I can run all test from some specific file/class, but again because of big number of that tests, It'll be time-consuming to run them continuously (I'm executing unit tests each time after saving a file in my IDE).

So in general I need some solution which will do following activities at a time:

  • Tracks which files have been changed since last file saving
  • Traces dependencies between code that have been changed in those files and unit tests which cover that code
  • Selectively executes only those unit tests which cover the code that has been affected

Does anyone have idea about something similar?

like image 670
Viktor Malyi Avatar asked Jan 17 '26 00:01

Viktor Malyi


2 Answers

You might like to checkout pytest-incremental:

The idea is to execute your tests faster by executing not all of them but only the “required” ones.

Install via pypi:

pip install pytest-incremental

Usage:

$ py.test --inc

I think it does what you are looking for, it "looks for imports recursively to find dependencies (using AST)" and runs only the changed tests.

like image 94
Andy Hayden Avatar answered Jan 19 '26 12:01

Andy Hayden


pytest-testmon is a pytest plugin which selects only tests affected by changes since last execution. It uses Coverage.py to track individual tests dependencies and and compares and saves checksums of methods on each execution.

like image 41
user257754 Avatar answered Jan 19 '26 12:01

user257754



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!