Skip to content

How to use "unittest" grader

Outvi V edited this page Mar 30, 2020 · 2 revisions

We added a new grader called unittest.

To use this, add in your init.yml:

unit_test: unit.py  # Your unittest file
test_cases:
- {points: 50}  # Up to you
- {points: 50}  # Up to you

And also patch your python modules at /usr/lib/python3.x/unittest/main.py:

--- a/main.py
+++ b/main.py
@@ -230,7 +230,7 @@
             # it is assumed to be a TestRunner instance
             testRunner = self.testRunner
         self.result = testRunner.run(self.test)
-        if self.exit:
+        if not self.result.wasSuccessful():
             sys.exit(not self.result.wasSuccessful())

 main = TestProgram

What's more, if you want to show the unittest results, such as:

.EEEEEE
========================================================

Then modify /usr/lib/python3.x/unittest/runner.py:

--- a/runner.py
+++ b/runner.py
@@ -134,7 +134,7 @@ class TextTestRunner(object):
         interface changes.
         """
         if stream is None:
-            stream = sys.stderr
+            stream = sys.stdout
         self.stream = _WritelnDecorator(stream)
         self.descriptions = descriptions
         self.verbosity = verbosity

(It's at the very end of this file. Line numbers may vary in different version.)

Clone this wiki locally