Skip to content

report results for ConcurrentStreamTestResults #292

@marqh

Description

@marqh

Hello Testtools

I am attempting to migrate from in situ unittest.TestCase

I am struggling to understand from the documentation how to obtain parallelisation and still report test results to the terminal.

I would like to propose an update to the documentation to explain this facet, once I have understood it.

I used to have

import unittest

class TestContentsConsistency(unittest.TestCase):
    def test_true(self):
        self.assertTrue(True)
    def test_false(self):
        self.assertTrue(False)

if __name__ == '__main__':
    unittest.main()

which outputs

> python3 ut.py 
F.
======================================================================
FAIL: test_false (__main__.TestContentsConsistency)
----------------------------------------------------------------------
Traceback (most recent call last):
  File "ut.py", line 6, in test_false
    self.assertTrue(False)
AssertionError: False is not true

----------------------------------------------------------------------
Ran 2 tests in 0.000s

FAILED (failures=1)

I have updated this to

import unittest
import testtools

class TestContentsConsistency(testtools.TestCase):
    def test_true(self):
        print('True')
        self.assertTrue(True)
    def test_false(self):
        print('False')
        self.assertTrue(False)

if __name__ == '__main__':
    suite = unittest.TestLoader().loadTestsFromTestCase(TestContentsConsistency)
    concurrent_suite = testtools.ConcurrentStreamTestSuite(lambda: ((case, None) for case in suite))
    concurrent_suite.run(testtools.StreamResult())

which outputs

> python3 tt.py 
False
True

so i can explicitly call a print statement, and see that the tests are running, but i do not get the unittest like summary output provided.

Questions:

  1. How can this example be adapted such that the test results are presented, similar to how unittest presents them?
  2. Is there value in turning this example with answers to question 1 into a tutorial within the documentation?

many thanks
marqh

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions