Skip to content

Instantly share code, notes, and snippets.

@usaturn
Created July 4, 2012 02:47
Show Gist options
  • Save usaturn/3044955 to your computer and use it in GitHub Desktop.
Save usaturn/3044955 to your computer and use it in GitHub Desktop.
引数のテストをするには?
# -*- coding:utf-8 -*-
# こんな感じで書くよーと教えてもらいました
import sys
import unittest
from StringIO import StringIO
from url_checker import *
class TestCaseForArgparse(unittest.TestCase):
def test_options_judgment(self):
# set STDERR to null
_stderr = sys.stderr
sys.stderr = StringIO()
sys.argv = ['script_name', '-a'] # set arguments
self.assertRaises(SystemExit, options_judgment)
sys.argv = [] # clear
sys.stderr = _stderr # restore STDERR
if __name__ == '__main__':
unittest.main()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment