craigahobbs / unittest-parallel

Parallel unit test runner for Python with coverage support
MIT License
29 stars 5 forks source link

unittest-parallel 1.2.x does not work with setUpClass and tearDownClass #9

Closed craigahobbs closed 3 years ago

craigahobbs commented 3 years ago
  1. 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())
  1. 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
craigahobbs commented 3 years ago

Added --class-fixtures and --module-fixtures options to properly execute tests with class and module fixtures, respectively.

craigahobbs commented 3 years ago

Released unittest-parallel 1.3.0