Travis CI AttributeError: object has no attribute 'assertCountEqual'

Travis CI AttributeError: object has no attribute 'assertCountEqual'

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

This build in Travis-CI 在执行 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 上的这个错误吗?

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 版本