mirror of
https://github.com/httprunner/httprunner.git
synced 2026-05-12 02:21:29 +08:00
test: add cli test
This commit is contained in:
36
tests/test_cli.py
Normal file
36
tests/test_cli.py
Normal file
@@ -0,0 +1,36 @@
|
||||
import io
|
||||
import sys
|
||||
import unittest
|
||||
|
||||
from httprunner.cli import main
|
||||
|
||||
|
||||
class TestCli(unittest.TestCase):
|
||||
|
||||
def setUp(self):
|
||||
self.captured_output = io.StringIO()
|
||||
sys.stdout = self.captured_output
|
||||
|
||||
def test_show_version(self):
|
||||
sys.argv = ["hrun", "-V"]
|
||||
|
||||
with self.assertRaises(SystemExit) as cm:
|
||||
main()
|
||||
sys.stdout = sys.__stdout__ # Reset redirect.
|
||||
|
||||
self.assertEqual(cm.exception.code, 0)
|
||||
|
||||
from httprunner import __version__
|
||||
self.assertIn(__version__, self.captured_output.getvalue().strip())
|
||||
|
||||
def test_show_help(self):
|
||||
sys.argv = ["hrun", "-h"]
|
||||
|
||||
with self.assertRaises(SystemExit) as cm:
|
||||
main()
|
||||
sys.stdout = sys.__stdout__ # Reset redirect.
|
||||
|
||||
self.assertEqual(cm.exception.code, 0)
|
||||
|
||||
from httprunner import __description__
|
||||
self.assertIn(__description__, self.captured_output.getvalue().strip())
|
||||
Reference in New Issue
Block a user