Search code examples
pythonunit-testingcode-coveragetravis-ci

Travis CI AttributeError: object has no attribute 'assertCountEqual'


I'm facing an issue in a remote build environment while using assertCountEqual from python's built-in unittest module.

This build in Travis-CI throws this error while executing coverage run -m unittest discover -v.

However, I'm able to execute the command on my local environment - Python 3.8.5 Ubuntu 20.04.

I tried removing the keys dictionary attribute from the test data, but even then the build failed on the remote environment and executed on my local environment.

test_bfs.py and test_dfs.py are the files on which the build fails, and this is repository.

This is the output on my local environment:

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

Can someone please let me know how I can fix this error on Travis?


Solution

  • there's a hint from the pip output:

    /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
    

    this is actually running python2.7 where assertCountEqual does not exist

    I'd suggest using python -m pip ... to install things -- this will make sure you're using the version of python you expect