【问题标题】:PyCharm "No tests were found"PyCharm“未找到测试”
【发布时间】:2018-02-18 16:31:36
【问题描述】:

这是我的主要代码

def return_first_name(first_name):
   return first_name

这是单元测试代码

import unittest
import profile


class TestFunctionFirstName(unittest.TestCase):
   def first_name(self):
      answer = profile.return_first_name("jakub")
      self.assertEqual(answer, "jakub")

我真的不明白为什么它没有找到任何单元测试。我已经坐了好几个小时了。

【问题讨论】:

  • 尝试将first_name 重命名为test_first_name
  • 它正在工作。浪费了我生命中的2个小时。谢谢诺里乌斯。

标签: python unit-testing syntax pycharm


【解决方案1】:

来自the docs

测试方法名称或函数名称应以“test_”开头,如test_example。名称与此模式不匹配的方法将不会作为测试执行。

因此,在您的情况下,您可以将测试方法重命名为

def test_first_name(self):

【讨论】:

  • 真的救了我的命!
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2021-09-24
  • 2018-04-05
  • 2016-09-02
  • 2019-08-07
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多