Mocking os.path.exists causes failures · Issue #416 · nedbat/coveragepy (original) (raw)

Originally reported by Anonymous


When coverage is run on the OpenStack Octavia project with version 4.0 of coverage multiple unit tests fail. However, if those unit tests are run without coverage or with version 3.7.1 of coverage the tests pass.

You can reproduce these errors with the following steps:

  1. Checkout Octavia:
    git fetch https://review.openstack.org/openstack/octavia refs/changes/48/225548/3 && git checkout FETCH_HEAD
  2. Change into the octavia directory: cd octavia
  3. Run the example tests:

The file path issue:
Passing test:
tox -e py27 -- octavia.tests.functional.amphorae.backend.agent.api_server.test_server.ServerTestCase.test_delete_listener
Failing test:
tox -e cover --
octavia.tests.functional.amphorae.backend.agent.api_server.test_server.ServerTestCase.test_delete_listener

The StopIteration issue:
Passing:
tox -e py27 -- octavia.tests.functional.amphorae.backend.agent.api_server.test_server.ServerTestCase.test_delete_cert
Fails:
tox -e cover --
octavia.tests.functional.amphorae.backend.agent.api_server.test_server.ServerTestCase.test_delete_cert

To test with version 3.7.1 of coverage edit the test-requirements.txt file:
replace: coverage>=3.6
with: coverage!=4.0,>=3.6

Run the above tox tests with the "r" flag to have it reload the python modules. Example:
tox -re cover --
octavia.tests.functional.amphorae.backend.agent.api_server.test_server.ServerTestCase.test_delete_listener

Note, the tests pass with version 3.7.1

Below is an example error when running with version 4.0:

#!text
======================================================================
FAIL: octavia.tests.functional.amphorae.backend.agent.api_server.test_server.ServerTestCase.test_delete_listener
tags: worker-1
----------------------------------------------------------------------
Traceback (most recent call last):
  File "/mnt/projects/coveragefix/octavia.cover/.tox/cover/local/lib/python2.7/site-packages/mock/mock.py", line 1305, in patched
    return func(*args, **keywargs)
  File "octavia/tests/functional/amphorae/backend/agent/api_server/test_server.py", line 196, in test_delete_listener
    mock_exists.assert_called_with('/var/lib/octavia/123/haproxy.cfg')
  File "/mnt/projects/coveragefix/octavia.cover/.tox/cover/local/lib/python2.7/site-packages/mock/mock.py", line 937, in assert_called_with
    six.raise_from(AssertionError(_error_message(cause)), cause)
  File "/mnt/projects/coveragefix/octavia.cover/.tox/cover/local/lib/python2.7/site-packages/six.py", line 692, in raise_from
    raise value
AssertionError: Expected call: exists('/var/lib/octavia/123/haproxy.cfg')
Actual call: exists('/usr/lib/python2.7/stringprep.py')