import unittest import sys import os sys.path.insert(0, os.path.abspath('..')) from ..point import Point class TestPoint(unittest.TestCase): def setUp(self): pass def xyCheck(self,x,y): point = Point(x,y) self.assertEqual(x,point.x) self.assertEqual(y,point.y) and this point.py, what I'm trying to test: import unittest from .utils import check_coincident, shift_point class Point(object): def __init__(self,x,y,mark={}): self.x = x self.y = y self.mark = mark def patched_coincident(self,point2): point1 = (self.x,self.y) return check_coincident(point1,point2) def patched_shift(self,x_shift,y_shift): point = (self.x,self.y) self.x,self,y = shift_point(point,x_shift,y_shift)
点击运行后提示:no tests were found
stackoverflow中给出了以下解决方案:
据了解PyCharm(或Intellij Idea Python插件)需要您的测试以满足以下条件,如果您希望在目录中运行所有测试时启动它们。
- 测试功能应以“test”开头(不需要下划线)
- 包含测试的文件也应该以“test”开头。“测试”(在我的情况下,资本T不起作用)
我使用Intellij IDEA 2016.3.5与Python插件
如果要使用命令行运行测试
python -m unittest
那么你应该添加__init__.py
到测试目录。Python仍然希望您的测试函数名称以“test”开头,您可以测试文件名以“test”开头,但是在文件的情况下,不关心第一个“t”是否为资本。TestCase和test_case同样适用。
解释2:
您可能想要检查的另一个问题是,如果您在控制台输出中看到“-k XXXX”取消选择 “ ## ”。这意味着您已将关键字添加到运行/调试配置,Pycharm将只运行其名称包含关键字的测试。