Commits

Kirill Simonov  committed 6a8bb2b

Added unittest gateway.

  • Participants
  • Parent commits 623a3f6

Comments (0)

Files changed (2)

 
 Fields:
 
-``doctest``: path patterns
+``doctest``: path pattern
     Files with doctest sessions.
 
 Example::
 
     doctest: test/test_*.rst
 
+Unittest
+--------
+
+This test case executes ``unittest`` test suite.
+
+Fields:
+
+``unittest``: path pattern
+    Files with unittest tests.
+
+Example::
+
+    unittest: test/test_*.py
+
 
 Custom Test Types
 =================

File src/pbbt/std.py

         self.ctl.passed()
 
 
+@Test
+class UnittestCase(BaseCase):
+    """Runs ``unittest`` tests."""
+
+    class Input:
+        unittest = Field(str,
+                hint="file pattern")
+
+    def check(self):
+        import unittest
+
+        # Load tests.
+        dirname = os.path.dirname(self.input.unittest)
+        basename = os.path.basename(self.input.unittest)
+        loader = unittest.TestLoader()
+        test = loader.discover(dirname, basename)
+
+        # Run tests.
+        report_stream = StringIO.StringIO()
+        runner = unittest.TextTestRunner(report_stream)
+        result = runner.run(test)
+        report = report_stream.getvalue()
+
+        # Report failures.
+        if not result.wasSuccessful():
+            self.ctl.failed("some tests failed")
+            self.ui.literal(report)
+            if self.ctl.training:
+                reply = self.ui.choice(None, ('', "halt"), ('c', "continue"))
+                if reply == '':
+                    self.ctl.halt()
+            return
+
+        self.ctl.passed()
+
+