您好我正在使用以下代码在我的代码中实现HTML测试运行器:
import HtmlTestRunner
import unittest
from io import StringIO
class TestStringMethods(unittest.TestCase):
""" Example test for HtmlRunner. """
def test_upper(self):
self.assertEqual('foo'.upper(), 'FOO')
def test_isupper(self):
self.assertTrue('FOO'.isupper())
self.assertFalse('Foo'.isupper())
def test_split(self):
s = 'hello world'
self.assertEqual(s.split(), ['hello', 'world'])
# check that s.split fails when the separator is not a string
with self.assertRaises(TypeError):
s.split(2)
def test_error(self):
""" This test should be marked as error one. """
raise ValueError
def test_fail(self):
""" This test should fail. """
self.assertEqual(1, 2)
@unittest.skip("This is a skipped test.")
def test_skip(self):
""" This test should be skipped. """
pass
if __name__ == '__main__':
unittest.main(testRunner=HtmlTestRunner.HTMLTestRunner(output='test_dir'))
但收到以下错误:
C:\ Users \ inswadhwa \ AppData \ Local \ Programs \ Python \ Python36-32 \ python.exe C:/Users/inswadhwa/PycharmProjects/automation/assertion.py Traceback(最近一次调用最后一次):文件“ C:/Users/inswadhwa/PycharmProjects/automation/assertion.py“,第2行,导入HTMLTestRunner文件”C:\ Users \ inswadhwa \ AppData \ Local \ Programs \ Python \ Python36-3 2 \ lib \ HTMLTestRunner .py“,第97行,导入StringIO ModuleNotFoundError:没有名为'StringIO'的模块进程以退出代码1完成
我已导入StringIO
。
有人可以建议一种克服这个问题的方法吗?
答案 0 :(得分:0)
看起来您正在使用this library,appears尚未更新以使用Python 3,其中the old StringIO
module has been replaced with the io.StringIO
class。
请尝试使用html-testRunner
。它应该适用于Python 3。