This is a demonstration of using a unittest.TestCaseRunner
to skip tests by label.
Labels are added with a decorator (by class), then test methods are replaced with a "force skip" wrapper before they're added to a test-suite.
This gist is in response to the stackoverflow question:
To try out this gist,
$ git clone [email protected]:a245f59bdcd457936c3b51aa2ebb3f6c.git
$ cd a245f59bdcd457936c3b51aa2ebb3f6c
$ ./runtests.py --whitelist foo
whitelisting labelled tests (skip everything else)
~/temp/a245f59bdcd457936c3b51aa2ebb3f6c (master) $ ./runtests.py --whitelist foo
test_foo (test_things.MyTest2) ... skipped 'label exclusion'
test_bar (test_things.MyTest3) ... skipped 'label exclusion'
test_one (test_things.MyTests1) ... ok
test_two (test_things.MyTests1) ... ok
----------------------------------------------------------------------
Ran 4 tests in 0.000s
OK (skipped=2)
blacklisting labelled tests
~/temp/a245f59bdcd457936c3b51aa2ebb3f6c (master) $ ./runtests.py --blacklist foo
test_foo (test_things.MyTest2) ... ok
test_bar (test_things.MyTest3) ... ok
test_one (test_things.MyTests1) ... skipped 'label exclusion'
test_two (test_things.MyTests1) ... skipped 'label exclusion'
----------------------------------------------------------------------
Ran 4 tests in 0.000s
OK (skipped=2)
Hi any idea if this could be possible at method level ?