Coming from PHPUnit, it was easy to group test classes or functions using the@group
annotation. That way I could run or exclude a very particular subset of tests, potentially across multiple files.
I'm wondering if python unittest has something similar. If that is the case how do I use it and run it from the CLI?
Thanks.
It is possible to run a group of test functions by putting them all in a single class. Let's say you have 4 test functions in your unittest and you want to have two groups of 2 functions. You need to create a tests.py script with two classes, each of which having 2 functions:
from unittest import TestCase
class testClass1(TestCase):
def testFunction1(self):
#test something
def testFunction2(self):
#test something
class testClass2(TestCase):
def testFunction3(self):
#test something
def testFunction4(self):
#test something
Then to run your unittest only on class 1 from command line, you can run
python -m unittest tests.testClass1
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With