Skip to content

unittest: it always terminates with zero (0) exit code regardless of failures #259

@belyalov

Description

@belyalov

except:
print(" FAIL")
test_result.failuresNum += 1
# Uncomment to investigate failure in detail
#raise
continue
finally:
tear_down()
def main(module="__main__"):
def test_cases(m):
for tn in dir(m):
c = getattr(m, tn)
if isinstance(c, object) and isinstance(c, type) and issubclass(c, TestCase):
yield c
m = __import__(module)
suite = TestSuite()
for c in test_cases(m):
suite.addTest(c)
runner = TestRunner()
result = runner.run(suite)

However, original implementation of unittest module takes care about failures:

def runTests(self):
    if self.testRunner is None:
        self.testRunner = TextTestRunner(verbosity=self.verbosity)
    result = self.testRunner.run(self.test)
    sys.exit(not result.wasSuccessful())

Unfortunately, micropython version doesn't.
Therefore it is unable to build CI for micropython - it will be always passing.

P.S. Fix is very straight forward - just add check for failures.

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