I want to show flag places in my Python unittests where I have been lazy and de-activated tests.
But I also have conditional executions that are not laziness, they are motivated by performance or system conditions at time of testing. Those are the skipUnless ones and I want to ignore them entirely.
Let's take some inputs that I have put in a file, test_so_bashregex.txt, with some comments.
!ignore this, because skipUnless means I have an acceptable conditional flag
@unittest.skipUnless(do_test, do_test_msg)
def test_conditional_function():
xxx
!catch these 2, lazy test-passing
@unittest.skip("fb212.test_urls_security_usergroup Test_Detail.test_related fails with 302")
def sometest_function():
xxx
@unittest.expectedFailure
def test_another_function():
xxx
!bonus points... ignore things that are commented out
# @unittest.expectedFailure
Additionally, I can't use a grep -v skipUnless
in a pipe because I really want to use egrep -A 3 xxx *.py
to give some context, as in:
grep -A 3 "@unittest\." *.py
test_backend_security_meta.py: @unittest.skip("rewrite - data can be legitimately missing")
test_backend_security_meta.py- def test_storage(self):
test_backend_security_meta.py- with getMultiDb() as mdb:
test_backend_security_meta.py-
What I have tried:
Trying @ https://www.debuggex.com/
I tried @unittest\.(.+)(?!(Unless\())
and that didn't work, as it matches the first 3.
Ditto @unittest\.[a-zA-Z]+(?!(Unless\())
@unittest\.skip(?!(Unless\())
worked partially, on the 2 with skip.
All of those do partial matches despite the presence of Unless.
on bash egrep, which is where this going to end up, things don't look much better.
jluc@explore$ egrep '@unittest\..*(?!(Unless))' test_so_bashregex.txt
egrep: repetition-operator operand invalid