【问题标题】:Travis CI AttributeError: object has no attribute 'assertCountEqual'Travis CI AttributeError:对象没有属性“assertCountEqual”
【发布时间】:2020-11-10 00:44:02
【问题描述】:

我在使用 python 的内置 unittest 模块中的 assertCountEqual 时在远程构建环境中遇到问题。

Travis-CI 中的This build 在执行coverage run -m unittest discover -v 时抛出此错误。

但是,我可以在本地环境 - Python 3.8.5 Ubuntu 20.04 上执行该命令。

我尝试从测试数据中删除 keys 字典属性,但即便如此,远程环境上的 build failed 并在我的本地环境中执行。

test_bfs.pytest_dfs.py 是构建失败的文件,这是repository

这是我本地环境的输出:

test_loop (tests.unit.test_bfs.TestBreadthFirstSearch)
Ensure no vertex points to itself. ... ok
test_number_of_vertices (tests.unit.test_bfs.TestBreadthFirstSearch)
Ensure that number of vertices is greater than 2. ... ok
test_valid_path_exists (tests.unit.test_bfs.TestBreadthFirstSearch)
Ensure a valid path exists for valid data, irrespective of order. ... ok
test_valid_path_not_none (tests.unit.test_bfs.TestBreadthFirstSearch)
Ensure valid path is returned for valid data. ... ok
test_loop (tests.unit.test_dfs.TestDepthFirstSearch)
Ensure no vertex points to itself. ... ok
test_number_of_vertices (tests.unit.test_dfs.TestDepthFirstSearch)
Ensure that number of vertices is greater than 2. ... ok
test_valid_path_exists (tests.unit.test_dfs.TestDepthFirstSearch)
Ensure a valid path exists for valid data, irrespective of order. ... ok
test_valid_path_not_none (tests.unit.test_dfs.TestDepthFirstSearch)
Ensure valid path is returned for valid data. ... ok
test_sequence (tests.unit.test_inorder_traversal.TestInOrderTraversal)
Compare expected output with tree structure. ... ok
test_common_ancestor (tests.unit.test_lowest_common_ancestor.TestLowestCommonAncestor)
Check whether node 2 is the ancestor of node 1. ... ok
test_different_branch_ancestor (tests.unit.test_lowest_common_ancestor.TestLowestCommonAncestor)
Verify ancestor when both nodes belong to different subtrees. ... ok
test_same_branch_ancestor (tests.unit.test_lowest_common_ancestor.TestLowestCommonAncestor)
Verify ancestor when both nodes belong to the same subtree. ... ok
test_sequence (tests.unit.test_postorder_traversal.TestPostOrderTraversal)
Compare expected output with tree structure. ... ok
test_sequence (tests.unit.test_preorder_traversal.TestPreOrderTraversal)
Compare expected output with tree structure. ... ok

----------------------------------------------------------------------
Ran 14 tests in 0.002s

OK

有人可以告诉我如何解决 Travis 上的这个错误吗?

【问题讨论】:

    标签: python unit-testing code-coverage travis-ci


    【解决方案1】:

    pip 输出有提示:

    /usr/local/lib/python2.7/dist-packages/pip/_vendor/requests/__init__.py:83: RequestsDependencyWarning: Old version of cryptography ([1, 2, 3]) may cause slowdown.
    
      warnings.warn(warning, RequestsDependencyWarning)
    
    DEPRECATION: Python 2.7 reached the end of its life on January 1st, 2020. Please upgrade your Python as Python 2.7 is no longer maintained. pip 21.0 will drop support for Python 2.7 in January 2021. More details about Python 2 support in pip, can be found at https://pip.pypa.io/en/latest/development/release-process/#python-2-support
    

    这实际上是在运行 python2.7 而assertCountEqual 不存在

    我建议使用 python -m pip ... 来安装东西——这将确保您使用的是您期望的 python 版本

    【讨论】:

    • 但是在执行测试用例之前,有python --version,输出Python 3.8.0。这还不够吗?
    • pythonpip 不是同一个可执行文件,因此它们可能来自不同的安装
    • 谢谢安东尼!我正在等待构建完成。
    • :) 我在项目根目录中有一个名为queue 的目录(其中还有一个类Queue),我认为这可能是导致问题的原因。我在这里看到github.com/eternnoir/pyTelegramBotAPI/issues/298这两个方面我会看看然后再确认。
    猜你喜欢
    • 2021-07-31
    • 2012-12-01
    • 2021-04-19
    • 2021-11-22
    • 1970-01-01
    • 1970-01-01
    • 2018-08-28
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多