Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Running unittest discover ignoring specific directory

I'm looking for a way of running python -m unittest discover, which will discover tests in, say, directories A, B and C. However, directories A, B and C have directories named dependencies inside each of them, in which there are also some tests which, however, I don't want to run.

Is there a way to run my tests satisfying these constraints without having to create a script for this?

like image 203
lucasnadalutti Avatar asked Sep 06 '16 21:09

lucasnadalutti


1 Answers

I've managed to do it this way (In *NIX):

find `pwd` -name '*_test.py' -not -path '*unwanted_path*' \
  | xargs python3 -m unittest -v

That is, the tests are discovered by find, which allows for options like path pattern exclusions, then they're passed to the unittest command as argument list.

Note that I had to switch to find pwd, where usually I can write find ., since relative paths in the form ./xxx aren't accepted by unittest (module not found).

like image 90
zakmck Avatar answered Oct 11 '22 18:10

zakmck