Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Coveralls uses internal undocumented parts of coverage.py #47

Closed
nedbat opened this issue Sep 27, 2014 · 5 comments
Closed

Coveralls uses internal undocumented parts of coverage.py #47

nedbat opened this issue Sep 27, 2014 · 5 comments
Assignees

Comments

@nedbat
Copy link

nedbat commented Sep 27, 2014

I'm heavily refactoring coverage.py for version 4.0. I tried to release an alpha, but it broke coveralls, and therefore many people's tests on Travis:

Submitting coverage to coveralls.io...
Traceback (most recent call last):
  File ".tox/coveralls/bin/coveralls", line 11, in <module>
    sys.exit(main())
  File "/home/travis/build/ionelmc/python-manhole/.tox/coveralls/lib/python2.7/site-packages/coveralls/cli.py", line 49, in main
    result = coverallz.wear()
  File "/home/travis/build/ionelmc/python-manhole/.tox/coveralls/lib/python2.7/site-packages/coveralls/api.py", line 73, in wear
    data = self.create_data()
  File "/home/travis/build/ionelmc/python-manhole/.tox/coveralls/lib/python2.7/site-packages/coveralls/api.py", line 122, in create_data
    self._data = {'source_files': self.get_coverage()}
  File "/home/travis/build/ionelmc/python-manhole/.tox/coveralls/lib/python2.7/site-packages/coveralls/api.py", line 132, in get_coverage
    return reporter.report()
  File "/home/travis/build/ionelmc/python-manhole/.tox/coveralls/lib/python2.7/site-packages/coveralls/reporter.py", line 27, in report
    self.parse_file(cu, self.coverage._analyze(cu))
  File "/home/travis/build/ionelmc/python-manhole/.tox/coveralls/lib/python2.7/site-packages/coveralls/reporter.py", line 58, in parse_file
    source_file = cu.source_file()
AttributeError: 'PythonCodeUnit' object has no attribute 'source_file'

We should work together on how to fix it.

@coagulant
Copy link
Contributor

I guess it's not too hard to make coveralls work with coverage 4.0b. However, adding newline to the end of python source file changes results a bit, compared to previous coverage version. Why is newline necessary?

@nedbat
Copy link
Author

nedbat commented Jan 10, 2015

Thanks for looking into updating the support. 4.0 is not in beta yet, so the interfaces still are not finished, so it may be early to write code.

The newline is only necessary in some places (compiling to bytecode), and I could adjust how it is done, but can you tell me what kind of result changes you are seeing? I don't worry if the result numbers shift up or down a little bit.

@coagulant
Copy link
Contributor

I'm using a custom reporter to get both coverage data and source file at the same time.
Here is a working report function, adapted to 4.0a2

def parse_file(self, cu, analysis):
        """ Generate data for single file """
        filename = cu.file_locator.relative_filename(cu.filename)
        coverage_lines = [self.get_hits(i, analysis) for i in range(1, len(cu.parser.lines) + 1)]
        source = cu.source()

        self.source_files.append({
            'name': filename,
            'source': source,
            'coverage': coverage_lines
        })

As coverage.py adds an empty newline to the end of the file, I'm seeing this extra line in sources and in coverage output. It's a minor discrepancy, but still...

Example: running coverage example/runtests.py results (full pytest output)

Coverage 3.X:

hits per line: [None, None, None, 1, 1, None, None, 1, None, None, None, 1, 0]
number of source lines in project.py: 13
json-encoded source as string: u'# coding: utf-8\n\n\ndef hello():\n    print(\'world\')\n\n\nclass Foo(object):\n    """ Bar """\n\n\ndef baz():\n    print(\'this is not tested\')'

Coverage 4.0a2:

hits per line: [None, None, None, 1, 1, None, None, 1, None, None, None, 1, 0, None]
number of source lines in project.py: 14
json-encoded source as string: u'# coding: utf-8\n\n\ndef hello():\n    print(\'world\')\n\n\nclass Foo(object):\n    """ Bar """\n\n\ndef baz():\n    print(\'this is not tested\')\n'

I don't think that adding one extra newline changes coverage numbers much, just wanted to let you know.

@coagulant coagulant self-assigned this Jan 10, 2015
@nedbat
Copy link
Author

nedbat commented Jan 21, 2015

Thanks for the explanation.

@coagulant
Copy link
Contributor

Closing this in favor of #81

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants