The following code path:
def _get_token(url, data):
print('will show covered')
response = requests.post(url, data=data)
print('will not show covered but will still print')
access_token = response.json().get('access_token')
return 'Bearer {0}'.format(access_token)
is causing coverage to incorrectly report its lines for us when run with requests_mock
:
import requests_mock
def test_parse_response(self):
with requests_mock.mock() as rm:
rm.post(token_url, status_code=200, json={'access_token': 'ACCESSTOKEN'})
self.assertEqual( _get_token(token_url, {}), 'Bearer ACCESSTOKEN')
The lines after the requests.post
line are being reported incorrectly on some machines (as in they are not reporting coverage the lines for those lines being covered). However, turning off wifi results in those lines working for coverage (?).
The tests are being run with tox and a tox.ini file in the root of the repo that sets the test command as:
[testenv]
nosetests --exclude-dir=mypackage/test/donttestme --cover-xml --cover-xml-file=coverage_file.xml
with a setup.cfg containing:
[nosetests]
with-coverage=true
cover-erase=true
cover-package=mypackage
cover-min-percentage=100
cover-branches=true
with-xunit=true
[coverage:report]
exclude_lines =
if __name__ == .__main__.:
pragma: no cover
I have narrowed down that:
- The codepath is being executed (the test would fail otherwise, the codepath has to be hit)
- Changing the requests_mock returns fail the test
- All versions of python/packages installed (both in virtual environment and globally) are the same
- codecov==2.0.5, coverage==4.2, nose==1.3.7, nose-exclude==0.4.1, requests==2.11.0, requests-mock==1.3.0,
- Versions of OSX are the same (10.11.6 - though people on other versions see this too)
- Verified etc/hosts is normal
- On macbook pro, retina's (so wifi disabling is through disabling with the menu option)
- The problem happens after
requests.post
- all future lines, exclusive of thepost
line, are not reported - The behavior is the same in tox for 27, 3.5, and 3.6 python
- Python has been installed with brew
- When tox is run from pyenv/virtualenvs both show the same behavior
The exact same codebase has worked fine both with/without wifi for about 50% of our team but the other 50% see the problematic behavior where coverage only is reporting correctly without wifi.
I'm completely out of ideas for what could be the issue here. Why could this happening?