[Tutor] unittest not working

Peter Otten __peter__ at web.de
Thu Nov 19 13:51:47 EST 2015


Mike wrote:

> I'm trying to unit test a self-built regular expression processor for  an
> assignment. I'm trying to set up unit tests for the package, but it's not
> executing them. This is my first time trying to use the unittest module,
> so I'm sure I'm missing something, I'm just not sure what. I even put a
> test case in there I knew would fail just to try it.
> 
> Unit Test code:
> import unittest
> from regex import regexp
> 
> class RegexTest(unittest.TestCase):
>     def fail_test(self):
>         self.assertEqual(1, 2)
> 
>     def basic_test(self):
>         self.assertEqual(regexp('Hello', 'Goodbye'), '')
>         self.assertEqual(regexp('hello', 'ello'), 'ello')
>         with self.assertRaises(SyntaxError):
>             regexp('hello', 'he)')
> 
> if __name__ == '__main__':
>     unittest.main()
> 
> Output:
>>>>
> 
> ----------------------------------------------------------------------
> Ran 0 tests in 0.000s
> 
> OK
> Exit code:  False
>>>>

Rename the mathods fail_test to test_fail, and basic_test to test_basic.

Test methods are recognized by their prefix.




More information about the Tutor mailing list