2

I have the following configuration in tox:

[tox]
envlist = py37

[testenv]
passenv = TRAVIS TRAVIS_*
setenv =
    DEFAULT_FROM = mock_email@mock.com
    DEFAULT_SERVER = mock_server
basepython =
    py37: python3.7
deps =
    -r{toxinidir}/requirements.txt
    -r{toxinidir}/test-requirements.txt
    nose
    pytest
    pytest-cov
sitepackages = False
commands =
    pytest {posargs} --cov
# Add the following line locally to get an HTML report --cov-report html:htmlcov-py37

And the following .coveragerc file:

[run]
branch=True
source=sync2jira/
omit=sync2jira/mailer.py

[report]
fail_under=60

But no matter what (even in Travis) python-coveralls can't seem to send the data to coveralls. I get the following error:

Submitting coverage to coveralls.io...
Traceback (most recent call last):
  File "/Users/sidpremkumar/Documents/Work/Sync2Jira/venv/lib/python3.7/site-packages/coverage/data.py", line 293, in read_file
    self.read_fileobj(f)
  File "/Users/sidpremkumar/Documents/Work/Sync2Jira/venv/lib/python3.7/site-packages/coverage/data.py", line 271, in read_fileobj
    data = self._read_raw_data(file_obj)
  File "/Users/sidpremkumar/Documents/Work/Sync2Jira/venv/lib/python3.7/site-packages/coverage/data.py", line 311, in _read_raw_data
    go_away = file_obj.read(len(cls._GO_AWAY))
  File "/Users/sidpremkumar/Documents/Work/Sync2Jira/venv/bin/../lib/python3.7/codecs.py", line 322, in decode
    (result, consumed) = self._buffer_decode(data, self.errors, final)
UnicodeDecodeError: 'utf-8' codec can't decode byte 0x96 in position 106: invalid start byte

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "/Users/sidpremkumar/Documents/Work/Sync2Jira/venv/bin/coveralls", line 8, in <module>
    sys.exit(main())
  File "/Users/sidpremkumar/Documents/Work/Sync2Jira/venv/lib/python3.7/site-packages/coveralls/cli.py", line 77, in main
    result = coverallz.wear()
  File "/Users/sidpremkumar/Documents/Work/Sync2Jira/venv/lib/python3.7/site-packages/coveralls/api.py", line 176, in wear
    json_string = self.create_report()
  File "/Users/sidpremkumar/Documents/Work/Sync2Jira/venv/lib/python3.7/site-packages/coveralls/api.py", line 192, in create_report
    data = self.create_data()
  File "/Users/sidpremkumar/Documents/Work/Sync2Jira/venv/lib/python3.7/site-packages/coveralls/api.py", line 246, in create_data
    self._data = {'source_files': self.get_coverage()}
  File "/Users/sidpremkumar/Documents/Work/Sync2Jira/venv/lib/python3.7/site-packages/coveralls/api.py", line 261, in get_coverage
    workman.load()
  File "/Users/sidpremkumar/Documents/Work/Sync2Jira/venv/lib/python3.7/site-packages/coverage/control.py", line 677, in load
    self.data_files.read(self.data)
  File "/Users/sidpremkumar/Documents/Work/Sync2Jira/venv/lib/python3.7/site-packages/coverage/data.py", line 653, in read
    data.read_file(self.filename)
  File "/Users/sidpremkumar/Documents/Work/Sync2Jira/venv/lib/python3.7/site-packages/coverage/data.py", line 297, in read_file
    filename, exc.__class__.__name__, exc,
coverage.misc.CoverageException: Couldn't read data from '/Users/sidpremkumar/Documents/Work/Sync2Jira/.coverage': UnicodeDecodeError: 'utf-8' codec can't decode byte 0x96 in position 106: invalid start byte

Any ideas why I'm getting this error? I've tried with coverage too instead of pytest but no luck.

  • Does this answer your question? [UnicodeDecodeError: 'utf8' codec can't decode byte 0x9c](https://stackoverflow.com/questions/12468179/unicodedecodeerror-utf8-codec-cant-decode-byte-0x9c) – Jordan Simba Dec 21 '19 at 22:23
  • Unfortunately not as pytest is generating the .coverage file and I have no control of it :( – Sid Premkumar Dec 22 '19 at 07:50
  • I have seen this as well in CI when gathering coverage information and calling `coverage` or `coveralls` with different Python interpreters (despite them having the same version). – Mathias Laurin Dec 29 '19 at 09:37
  • I am using Python 3.7 both in Tox and in the .travis.yml :( – Sid Premkumar Dec 29 '19 at 16:26

2 Answers2

2

You may be using a major version of coverage which is incompatible with your version of pytest and/or pytest-cov. Make sure if you're using coverage 5.0, which was just released on December 14th, that you're also using the latest versions of these other modules.

Can you share your requirements.txt?

Dan Wild
  • 36
  • 3
  • You can check out the PR here: https://github.com/sidpremkumar/Sync2Jira/pull/30 – Sid Premkumar Jan 02 '20 at 21:15
  • This looked like it was the issue. I needed to upgrade to `coverage 5.0.1` and then instead of running `pytest arg1 arg2` I had to run `covrage -m pytest arg1 arg2` in my `tox.ini` file. All working now thank you! – Sid Premkumar Jan 03 '20 at 10:04
0

In my case removing the .tox hidden folder of the project and re-running tox worked.

I was seeing:

report installed: coverage==4.5.4

and I now see:

report installed: coverage==5.0.3
Stéphane Bruckert
  • 21,706
  • 14
  • 92
  • 130