我正在尝试使用Selenium + Python,在研究了一些关于生成报告的好方法后,我遇到了“HTMLTestRunner”,问题是我已经找了很多关于互联网和他们是一样的但是当我试图让它来处理我的代码(主要是按戏)时,我看不到生成的报告而且我没有收到任何错误,你能帮我一把吗?请?这是我正在使用的代码: python36 硒3.3.1 pycharm Community Edition 2016.3.2
# coding=utf-8
import unittest
import HTMLTestRunner
import os
from test_project.count import Count
# get the directory path to output report file
result_dir = os.getcwd()
class TestCount(unittest.TestCase):
def setUp(self):
self.j =Count(2,3)
def test_add(self):
self.add = self.j.add()
self.assertEqual(self.add,5)
def tesrDown(self):
pass
# get all tests from SearchProductTest and HomePageTest class
if __name__ == '__main__':
suit = unittest.TestSuite()
suit.addTest(TestCount("test_add"))
smoke_tests = unittest.TestSuite(suit)
outfile = open(result_dir + '\SmokeTestReport.html', 'wb')
runner = HTMLTestRunner.HTMLTestRunner(stream=outfile,
title='Test Report',
description='Smoke Tests')
runner.run(smoke_tests)
删除主要部分之后的工作。任何人都可以告诉我为什么?
# coding=utf-8
import unittest
import HTMLTestRunner
import os
from test_project.count import Count
# get the directory path to output report file
result_dir = os.getcwd()
class TestCount(unittest.TestCase):
def setUp(self):
self.j =Count(2,3)
def test_add(self):
self.add = self.j.add()
self.assertEqual(self.add,5)
def tesrDown(self):
pass
suit = unittest.TestSuite()
suit.addTest(TestCount("test_add"))
smoke_tests = unittest.TestSuite(suit)
outfile = open(result_dir + '\SmokeTestReport.html', 'wb')
# configure HTMLTestRunner options
runner = HTMLTestRunner.HTMLTestRunner(stream=outfile,
title='Test Report',
description='Smoke Tests')
# run the suite using HTMLTestRunner
runner.run(smoke_tests)
答案 0 :(得分:1)
您不能在程序中运行Unittest。它不会执行主要部分。 只需编辑配置即可运行脚本。
像这样: 从“运行”菜单>“运行”>“编辑配置”>选择/添加Python上方的ScriptName.py,而不是ScriptName.py中的单元测试
参考: pycharm-wont-allow-to-run-a-file-shows-run-unittest-option-only