Python 3.3:使用nose.tools.assert_equals时出现DeprecationWarning

2024-03-28

我正在使用nosetest工具来断言pythonunittest https://docs.python.org/3.3/library/unittest.html:

...
from nose.tools import assert_equals, assert_almost_equal

class TestPolycircles(unittest.TestCase):

    def setUp(self):
        self.latitude = 32.074322
        self.longitude = 34.792081
        self.radius_meters = 100
        self.number_of_vertices = 36
        self.vertices = polycircles.circle(latitude=self.latitude,
                                           longitude=self.longitude,
                                           radius=self.radius_meters,
                                           number_of_vertices=self.number_of_vertices)

    def test_number_of_vertices(self):
        """Asserts that the number of vertices in the approximation polygon
        matches the input."""
        assert_equals(len(self.vertices), self.number_of_vertices)

    ...

当我跑步时python setup.py test,我收到弃用警告:

...
Asserts that the number of vertices in the approximation polygon ...
/Users/adamatan/personal/polycircles/polycircles/test/test_polycircles.py:22:    
DeprecationWarning: Please use assertEqual instead.
  assert_equals(len(self.vertices), self.number_of_vertices)
ok
...

我找不到任何assertEqual在鼻子工具中。这个警告来自哪里,我该如何解决它?


The nose.tools assert_*函数只是自动创建的 PEP8aliases为了TestCase方法,所以assert_equals是相同的TestCase.assertEquals().

然而,后者只是曾经alias for TestCase.assertEqual() (note: 没有尾随s)。该警告旨在告诉您,而不是TestCase.assertEquals()你需要使用TestCase.assertEqual() as the 别名已被弃用 http://bugs.python.org/issue9424.

For nose.tools这转化为使用assert_equal(没有尾随s):

from nose.tools import assert_equal, assert_almost_equal

def test_number_of_vertices(self):
    """Asserts that the number of vertices in the approximation polygon
    matches the input."""
    assert_equal(len(self.vertices), self.number_of_vertices)

你用过吗assert_almost_equals(带有尾随s),你会看到类似的警告来使用assertAlmostEqual,还有。

本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)

Python 3.3:使用nose.tools.assert_equals时出现DeprecationWarning 的相关文章

  • python中热图的层次聚类

    我有一个 NxM 矩阵 其值范围为 0 到 20 我可以使用 Matplotlib 和 pcolor 轻松获得热图 现在我想使用 scipy 应用层次聚类和树状图 我想重新排序每个维度 行和列 以显示哪些元素相似 根据聚类结果 如果矩阵是方
  • Pip install 导致此错误“ cl.exe' failed with exit code 2 ”

    我已经阅读了有关此错误的所有其他问题 但令人沮丧的是 没有一个给出有效的解决方案 如果我跑pip install sentencepiece在命令行中 它给出了以下输出 src sentencepiece sentencepiece wra
  • 创建圆形图像 PIL Tkinter

    Currently I have a zoom feature in my application that works very well however I d like the actual zoom box to be a circ
  • 将 matplotlib png 转换为 base64 以在 html 模板中查看

    背景 你好 我正在尝试制作一个简单的网络应用程序 按照教程计算阻尼振动方程 并将结果的 png 返回到 html 页面 然后将其转换为 Base64 字符串 Problem 该应用程序运行正常 只是在计算结果时返回损坏的图像图标 可能是因为
  • 可移植的非关系数据库

    我想尝试 尝试非关系数据库 最好的解决方案是 便携式 这意味着它不需要安装 理想情况下 只需将目录复制粘贴到某个地方即可使其工作 我不介意第一次使用时是否需要编辑一些配置文件或运行配置工具 可从 python 访问 适用于 Windows
  • 在加载“cv2”二进制扩展期间检测到递归

    我有一个小程序 在 pyinstaller 编译后返回 opencv 错误 但无需编译即可工作 我在 Windows 10 上使用 Python 3 8 10 Program 导入 pyautogui将 numpy 导入为 np导入CV2
  • 使用 Python 的文本中的词频但忽略停用词

    这给了我文本中单词的频率 fullWords re findall r w allText d defaultdict int for word in fullWords d word 1 finalFreq sorted d iterit
  • Pyinstaller --onefile 警告文件已存在但不应存在

    跑步时Pyinstaller onefile 并开始得到结果 exe 会出现多个弹出窗口 并显示以下警告 WARNING file already exists but should not C Users myuser AppData L
  • 如何使用python读取最后一行的特定位置

    我有一个太大的 txt 文件 并且有几行类似的行 如下所示 字1 字2 字3 字4 553 75 我对位置 4 值 感兴趣 即最后一行 553 75 我的文件文本 word1 word2 word3 word4 553 20 word1 w
  • 如何使用 jira-python 设置 fixVersions 字段

    我正在尝试使用 jira python 模块 http jira python readthedocs org en latest 更新现有的 JIRA 具体来说 我正在尝试设置问题的fixesVersion 列表 我已经尝试了一段时间但没
  • 如何在matplotlib中基于x轴更改直方图颜色

    我有根据 pandas 数据框计算出的直方图 我想根据 x 轴值更改颜色 例如 If the value is 0 the color should be green If the value is gt 0 the color shoul
  • 请求response.iter_content()获取不完整的文件(1024MB而不是1.5GB)?

    您好 我一直在使用此代码片段从网站下载文件 到目前为止 小于 1GB 的文件都很好 但我注意到 1 5GB 文件不完整 s is requests session object r s get fileUrl headers headers
  • 向量化 numpy bincount

    我有一个 2d numpy 数组 A我要申请np bincount 到矩阵的每一列A生成另一个二维数组B由原始矩阵每列的 bincounts 组成A 我的问题是 np bincount 是一个采用一维数组的函数 它不是像这样的数组方法B A
  • psutil:测量特定进程的CPU使用率

    我正在尝试测量进程树的 cpu 使用率 目前获取进程 没有子进程 的 cpu usage 就可以了 但我得到了奇怪的结果 import psutil p psutil Process PID p cpu percent 还给我float g
  • 测试中的模型 - Django 1.7 问题

    我正在尝试将我的项目移植为使用 Django 1 7 除了一件事之外 一切都很好 测试文件夹内的模型 Django 1 7 新迁移在内部运行 migrate 命令 在运行syncdb之前 这意味着如果模型未包含在迁移中 它将不会填充到数据库
  • Jinja2中获取请求参数

    如何检索请求参数a在 Jinja2 模板中 http foo bar a 1 我这个答案有点晚了 但其他解决方案并没有真正考虑到您对 Flask 的使用 事实上 您将 Flask 与 Jinja2 一起使用 这使得您的情况与其他框架有点不同
  • 如何使用 Python 将我的 GoPro Hero 4 相机直播连接到 openCV?

    我在尝试从我的新 GoPro Hero 4 相机捕获实时流并使用 openCV 对其进行一些图像处理时遇到麻烦 这是我的试用 创建的窗口上没有显示任何内容 import cv2 import argparse import time imp
  • 在Python中从列表中获取n个项目组的惯用方法? [复制]

    这个问题在这里已经有答案了 给定一个列表 A 1 2 3 4 5 6 是否有任何惯用的 Pythonic 方式来迭代它 就好像它是 B 1 2 3 4 5 6 除了索引之外 这感觉像是 C 的遗留物 for a1 a2 in A i A i
  • Selenium Python 使用代理运行浏览器[重复]

    这个问题在这里已经有答案了 我正在尝试编写一个非常简单的脚本 该脚本从 txt 文件获取代理 不需要身份验证 并用它打开浏览器 然后沿着代理列表循环此操作一定次数 我确实知道如何打开 txt 文件并使用它 我的主要问题是让代理正常工作 我见
  • Shap - 颜色条不显示在摘要图中

    显示summary plot时 不显示颜色条 shap summary plot shap values X train 我尝试过改变plot size 当绘图较高时 会出现颜色条 但它非常小 看起来不应该 shap summary plo

随机推荐