no tests were found? 解決辦法


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插件)需要您的測試以滿足以下條件,如果您希望在目錄中運行所有測試時啟動它們。

  1. 測試功能應以“test”開頭(不需要下划線)
  2. 包含測試的文件也應該以“test”開頭。“測試”(在我的情況下,資本T不起作用)

我使用Intellij IDEA 2016.3.5與Python插件

如果要使用命令行運行測試

 

python -m unittest

 那么你應該添加__init__.py到測試目錄。Python仍然希望您的測試函數名稱以“test”開頭,您可以測試文件名以“test”開頭,但是在文件的情況下,不關心第一個“t”是否為資本。TestCase和test_case同樣適用。

 

解釋2:

您可能想要檢查的另一個問題是,如果您在控制台輸出中看到“-k XXXX”取消選擇 “ ## ”。這意味着您已將關鍵字添加到運行/調試配置,Pycharm將只運行其名稱包含關鍵字的測試。


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM