- android - 多次调用 OnPrimaryClipChangedListener
- android - 无法更新 RecyclerView 中的 TextView 字段
- android.database.CursorIndexOutOfBoundsException : Index 0 requested, 光标大小为 0
- android - 使用 AppCompat 时,我们是否需要明确指定其 UI 组件(Spinner、EditText)颜色
我认为这更像是一个 PyCharm 问题,而不是单元测试问题,但我正在从一本书中学习测试,而这个示例让我失败了。我正在运行 PyCharm 2016.3.2 和 Python 3.6
import unittest
from name_function import get_formatted_name
class NamesTestCase(unittest.TestCase):
"""Tests for 'name_function.py'."""
def test_first_last_name(self):
"""Do names like 'Janis Joplin' work?"""
formatted_name = get_formatted_name('janis', 'joplin')
self.assertEqual(formatted_name, 'Janis Joplin')
# In book, it's just the unittest.main() , which does not work...
# So in PyCharm __name__ doesn't equal __main__ ... not sure why
# if __name__ == '__main__':
unittest.main()
这是 name_function.py:
def get_formatted_name(first, last):
"""Generate a neatly formatted full name."""
full_name = first + " " + last
return full_name.title()
如果我按照编写的方式运行它,则会收到以下错误:
EE
======================================================================
ERROR: test_name_function (unittest.loader._FailedTest)
----------------------------------------------------------------------
AttributeError: module '__main__' has no attribute 'test_name_function'
======================================================================
ERROR: true (unittest.loader._FailedTest)
----------------------------------------------------------------------
AttributeError: module '__main__' has no attribute 'true'
----------------------------------------------------------------------
Ran 2 tests in 0.000s
如果我让“if”语句运行(或者只是删除对unittest.main()的调用),那么它就会正常工作,根本没有main()调用。
这一切都在 test_name_function.py
中。因此,在运行这个文件(并导入 name_function.py
)时,PyCharm 似乎并不认为这个文件是 __main__
? PyCharm 是否在幕后做了其他事情?
我是 Python 和 PyCharm 的新手,正在尝试了解其结构和环境。非常感谢大家。
最佳答案
你可以用这个方法来算出来。
suite = unittest.defaultTestLoader.loadTestsFromTestCase(NamesTestCase)
unittest.TextTestRunner().run(suite)
关于python - 在 PyCharm 中调用 unittest.main() - AtrributeError : module '__main__' has no atrribute,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/42791270/
我知道可以在类型前添加#noinspection PyPep8Naming,但我想不通如何为单个文件全局设置。 我发现此功能适用于 some other JetBrains IDEs , 但未能在 P
我认为,在 PyCharm 的模块中重构函数名称通常会在项目范围内重构对该函数名称的任何使用。但是,我注意到项目中的笔记本中的功能没有被重构。重构时有没有办法包含笔记本? 我注意到 jupyter n
我需要使用 HTMLTestRunner 生成测试报告,因为该代码(位于文件末尾)是: suite = unittest.TestLoader().loadTestsFromTestCase(Test
Local History 是 Jetbrains IDE 系列(包括 Pycharm)绝对基础/关键的功能。为什么 .ipynb 文件会丢失?这是右键单击/上下文菜单 - 其中缺少 Show His
正如问题所问,如何在整个项目中的pycharm中运行查找/替换单词? 最佳答案 Edit | Find | Replace in Path。 快捷方式:Ctrl + Shift + R 关于pycha
我最近从 Spyder 更改为 PyCharm 作为 Python IDE。在 Spyder 中,我经常使用变量资源管理器功能(见图)。 PyCharm 中也提供此功能吗? 我找到了这个here ,“
嗨,我正在使用 pycharm 进行 python 开发。在 pycharm 中打开我的 python 项目时,它的打开方式如下图所示,其中我的项目名称是election,在此之前出现的选项卡都是父目
在 PyCharm 中,我的项目窗口中有一个文件夹是红色的。当所有其他文件夹都是蓝色时,该颜色意味着什么?我在 Git 中有我的项目,它主要是 Python,在 repo 中有一个 Java GUI。
我在我的 PyCharm 项目/文件栏中看到了这个: 我不确定这意味着什么,也不知道我为什么要这么做。谷歌搜索似乎没有提供任何有用的信息。有谁知道它是什么以及如何删除它?此外,项目中没有其他数字(没有
似乎 Pycharm 中的折叠自定义区域在某些缩进级别后不起作用。 这个不起作用: def test_a(): def function(): for g in group:
每当我创建一个函数、将其设为 View 并将模板映射到其上时,PyCharm 中的自动完成功能都会起作用。如果您输入类似 {{ book. }},其中 book 是一个模型,并且是您的上下文对象之一,
很长一段时间以来,我一直在寻找一种在 PyCharm 中折叠评论的方法。基本上我一直在寻找一种方法来实现与代码块相同的 + 注释。 最佳答案 用很容易做到这一点 #region Description
我正在使用 PyCharm 社区版 2016,我注意到我无法打开大数据输入文件或日志 (20MB)。编辑器只是说“文件 XXX 太大 (SIZE)”。 不仅如此,似乎也没有办法改变极限。官方文档提到了
在 PyCharm 中,我的项目窗口中有一个文件夹是红色的。当所有其他文件夹都是蓝色时,该颜色意味着什么?我在 Git 中有我的项目,它主要是 Python,在 repo 中有一个 Java GUI。
我想为 Pycharm 中的每个项目使用单独的虚拟环境。为此,我为每个项目创建了一个虚拟环境。我找不到清晰的文档 如果我想通过 PIP 命令添加或删除内容时需要为每个项目激活/停用这些虚拟环境,或者在
PyCharm 中是否有智能区分大小写搜索? 过去,我使用了一个编辑器,如果我使用小写字母,它会进行不区分大小写的搜索。 一旦我使用了第一个大写字符,搜索就区分大小写。 我喜欢这个。 我可以在 PyC
我已经按照 https://www.jetbrains.com/help/pycharm/requirements-installation-and-launching.html#linux 上的说明
有什么问题? 我在 PyCharm(版本 2016.1.4)中使用远程解释器(不是调试服务器!)进行远程调试,如下所述:jetbrains website . 当我在 Debug模式下运行时,程序会在
tldr;我希望我可以进入一个特定的程序状态,然后停止,然后继续编辑同一个文件,并使用这个过程迭代地向文件添加代码。 详情: 我经常想做的是使用python控制台或者在特定的程序状态下运行一段特定的代
有没有办法选择 PyCharm 中当前选定行下方的所有行(类似于在 Mac 中您可以使用 Cmd + Shift + down 选择行)? Cmd + Shift + right/left 工作正常,
我是一名优秀的程序员,十分优秀!