Copy-paste the following text into the "tests.py" file in an empty directory:
import random
import time
import unittest
class Tests1(unittest.TestCase):
@classmethod
def setUpClass(cls):
print('=== setUpClass')
assert not hasattr(cls, 'bar')
cls.bar = None
@classmethod
def tearDownClass(cls):
print('=== tearDownClass')
assert cls.bar is None
del cls.bar
def setUp(self):
print('=== setUp')
assert not hasattr(self, 'foo')
self.foo = None
def tearDown(self):
print('=== tearDown')
assert self.foo is None
del self.foo
def test_1(self):
time.sleep(random.random())
def test_2(self):
time.sleep(random.random())
class Tests2(unittest.TestCase):
def test_1(self):
time.sleep(random.random())
def test_2(self):
time.sleep(random.random())
In the directory from step 1, execute the following:
unittest-parallel -v
Actual output - notice setUpClass and tearDownClass are not called:
=== setUp
=== setUp
=== tearDown
test_2 (tests.Tests1) ... ok
test_2 (tests.Tests2) ... ok
test_1 (tests.Tests2) ... ok
=== tearDown
test_1 (tests.Tests1) ... ok
----------------------------------------------------------------------
Ran 4 tests in 0.895s
OK
Expected output:
=== setUpClass
=== setUp
=== tearDown
test_1 (tests.Tests1) ... ok
=== setUp
=== tearDown
test_2 (tests.Tests1) ... ok
=== tearDownClass
test_1 (tests.Tests2) ... ok
test_2 (tests.Tests2) ... ok
----------------------------------------------------------------------
Ran 4 tests in 1.215s
OK
Actual output - notice setUpClass and tearDownClass are not called:
Expected output: