SOLVED 3.3, 3.4b crash when running basic example of unittest
-
https://docs.python.org/3/library/unittest.html#basic-example
Maybe not crash, but it rather closes RoboFont
...
When I open it RoboFont back, the python file is loaded from a backup? Cool, new feature in 3.4, right?
-
as there is no module in the main:
import unittest class TestStringMethods(unittest.TestCase): def test_upper(self): self.assertEqual('foo'.upper(), 'FOO') def test_isupper(self): self.assertTrue('FOO'.isupper()) self.assertFalse('Foo'.isupper()) def test_split(self): s = 'hello world' self.assertEqual(s.split(), ['hello', 'world']) # check that s.split fails when the separator is not a string with self.assertRaises(TypeError): s.split(2) if __name__ == '__main__': loader = unittest.TestLoader() tests = [] for _, obj in list(locals().items()): try: if issubclass(obj, unittest.TestCase): tests.append(loader.loadTestsFromTestCase(obj)) except: pass suite = unittest.TestSuite(tests) runner = unittest.TextTestRunner() result = runner.run(suite) print(result)
-
Good, thanks a lot! :) But maybe I am doing something wrong. Running this outside of RoboFont tells that tests were done and in RoboFont it tells me that 0 tests were done in 0 seconds.
-
you can disable exit with:
import unittest class TestStringMethods(unittest.TestCase): def test_upper(self): self.assertEqual('foo'.upper(), 'FOO') def test_isupper(self): self.assertTrue('FOO'.isupper()) self.assertFalse('Foo'.isupper()) def test_split(self): s = 'hello world' self.assertEqual(s.split(), ['hello', 'world']) # check that s.split fails when the separator is not a string with self.assertRaises(TypeError): s.split(2) if __name__ == '__main__': result = unittest.main(exit=False) print(result)
-
and the feature to recover code after a crash was available since the start!!
-
Dont exit when finished ;) no crash but unittest stops the process