ãã¹ãããã¨ã skip ã¨docstring ã¡ã¢
ã»ãã¼
ç¥ããªãã£ãã®ã§ã¾ã¨ãã¦ãã
ãã¹ãã skip ãããã¨ã㯠@skip ãã³ã¬ã¼ã¿ã使ãã
åè::26.3. unittest — Unit testing framework — Python v3.4.0a1 documentation
å®é㯠Django ã§ãã£ã¦ããã©ä¸èº«ã¯ä¼¼ã¦ãã¯ã*1ãã¾ãã¾ãå¼ç¨ããã¨
class MyTestCase(unittest.TestCase): @unittest.skip("demonstrating skipping") def test_nothing(self): self.fail("shouldn't happen") @unittest.skipIf(mylib.__version__ < (1, 3), "not supported in this library version") def test_format(self): # Tests that work for only a certain version of the library. pass @unittest.skipUnless(sys.platform.startswith("win"), "requires Windows") def test_windows_support(self): # windows specific testing code pass
çµæã¯
test_format (__main__.MyTestCase) ... skipped 'not supported in this library version' test_nothing (__main__.MyTestCase) ... skipped 'demonstrating skipping' test_windows_support (__main__.MyTestCase) ... skipped 'requires Windows' ---------------------------------------------------------------------- Ran 3 tests in 0.005s OK (skipped=3)
ã³ã¡ã³ãã¢ã¦ãã㦠TODO ãã㦠pass ãã¦ããã©ããã®ã»ããããããããã§ããã
@kk6 ++
ãã¹ãã§è½ã¡ãæã®ããã« docstring ã¯1è¡ç®ã«ãµããªã¼ããã
class MyTestCase(unittest.TestCase): """Myã«ã¤ãã¦ã®ãã¹ã""" def test_nothing(self): """æ£å¸¸ç³»""" self.assertEqual(1,1) def test_nothing2(self): """æ£å¸¸ç³»2 è¤æ°è¡ã«æ¸¡ãå ´å """ self.assertEqual(1,1) def test_nothing3(self): """ æ£å¸¸ç³»3 è¤æ°è¡ã«æ¸¡ãå ´å """ self.assertEqual(1,1)
1è¡ã§ç°¡åã«åã¾ãã¨ãã¯ãããã©ããããããªãæã test_nothing2 ã¿ããã«1è¡ç®ã«ãããã¨ã§è½ã¡ãæã«ã¨ã©ã¼ã¡ãã»ã¼ã¸ã¨ãã¦è¡¨ç¤ºãã¦ãããããããããããã¯ãããããã
ãã ããã¹ãã³ã¼ããããªãã³ã¼ãé¨åã§è¤æ°è¡ã® docstring ã¯æ¹è¡ã㦠test_nothing3 ã¿ããã«æ¹è¡ããã»ãã好ãããª
*1:from django.utils.unittest import skip ããã£ã