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

Can't get code coverage to work.... #1731

Closed
1 of 3 tasks
alan412 opened this issue Aug 23, 2018 · 10 comments · Fixed by #1739
Closed
1 of 3 tasks

Can't get code coverage to work.... #1731

alan412 opened this issue Aug 23, 2018 · 10 comments · Fixed by #1739

Comments

@alan412
Copy link
Contributor

alan412 commented Aug 23, 2018

  • I'm submitting a ...
  • bug report
  • feature request
  • question about the decisions made in the repository
  • Do you want to request a feature or report a bug?
    I don't know if it is a bug or just my not knowing what I am doing.

  • What is the current behavior?
    When I try to execute covercp.py, I get the following:

(venv3) Honeycrisp2018:CheckMeIn alan$ python venv3/lib/python3.6/site-packages/cherrypy/lib/covercp.py 
Traceback (most recent call last):
  File "venv3/lib/python3.6/site-packages/cherrypy/lib/covercp.py", line 391, in <module>
    serve(*tuple(sys.argv[1:]))
  File "venv3/lib/python3.6/site-packages/cherrypy/lib/covercp.py", line 377, in serve
    if coverage is None:
UnboundLocalError: local variable 'coverage' referenced before assignment

If I comment out lines 377 and 378 then it will start up, but I get the following on the left hand side:
500 Internal Server Error

The server encountered an unexpected condition which prevented it from fulfilling the request.

Traceback (most recent call last):
  File "/Users/alan/Projects/CheckMeIn/venv3/lib/python3.6/site-packages/cherrypy/_cprequest.py", line 630, in respond
    self._do_respond(path_info)
  File "/Users/alan/Projects/CheckMeIn/venv3/lib/python3.6/site-packages/cherrypy/_cprequest.py", line 689, in _do_respond
    response.body = self.handler()
  File "/Users/alan/Projects/CheckMeIn/venv3/lib/python3.6/site-packages/cherrypy/lib/encoding.py", line 264, in __call__
    ct.params['charset'] = self.find_acceptable_charset()
  File "/Users/alan/Projects/CheckMeIn/venv3/lib/python3.6/site-packages/cherrypy/lib/encoding.py", line 173, in find_acceptable_charset
    if encoder(self.default_encoding):
  File "/Users/alan/Projects/CheckMeIn/venv3/lib/python3.6/site-packages/cherrypy/lib/encoding.py", line 114, in encode_string
    for chunk in self.body:
  File "venv3/lib/python3.6/site-packages/cherrypy/lib/covercp.py", line 325, in menu
    tree = get_tree(base, exclude, self.coverage)
  File "venv3/lib/python3.6/site-packages/cherrypy/lib/covercp.py", line 280, in get_tree
    runs = coverage.data.executed_files()
AttributeError: 'CoverageData' object has no attribute 'executed_files'
  • What is the expected behavior?
    I would really like (and think would be great to have in the documentation) an example using code coverage of one of the tutorial projects. I suspect I am just doing something not very smart.

  • What is the motivation / use case for changing the behavior?
    I would like to use code coverage to make sure my tests are covering enough of the project for a release.

  • Please tell us about your environment:

  • CherryPy version: 17.3.0
    -Python 3.6.1
  • Python version: 3.6.X
@webknjaz
Copy link
Member

Hi, this module is very old and it looks like nobody tested it for a decade. Does pytest-cov work for you?

@alan412
Copy link
Contributor Author

alan412 commented Sep 3, 2018 via email

@webknjaz
Copy link
Member

webknjaz commented Sep 3, 2018

Do you use pytest for testing? It should be able to pick up cov plugin if you pip install pytest-cov

@alan412
Copy link
Contributor Author

alan412 commented Sep 3, 2018 via email

@webknjaz
Copy link
Member

webknjaz commented Sep 3, 2018

I don't yet know, but it's used in CI while testing CherryPy itself. Tell us about your experience once you try :)

@webknjaz
Copy link
Member

webknjaz commented Sep 3, 2018

This might result in a good enhancement of documentation.

@webknjaz
Copy link
Member

webknjaz commented Sep 3, 2018

cc @jaraco

@jaraco
Copy link
Member

jaraco commented Sep 3, 2018

I don't know anything about covercp. That module clearly has bugs and it's not clear how to use it. I welcome PRs to improve that module and the documentation around how to use it. Whoever works on that will have to spend some time troubleshooting and establishing an understanding of that module and it's purpose(s).

@alan412
Copy link
Contributor Author

alan412 commented Sep 3, 2018 via email

@webknjaz
Copy link
Member

webknjaz commented Sep 3, 2018

@alan412 that would be lovely! The docs source is here: https://github.com/cherrypy/cherrypy/tree/master/docs

I believe that this module facilitated coverage in times of unittest and nose libs and now it's probably redundant:

cherrypy.engine.subscribe('start', covercp.start)

alan412 added a commit to alan412/cherrypy that referenced this issue Sep 6, 2018
webknjaz added a commit that referenced this issue Jul 3, 2019
PR #1791 by @jaraco.

TODO: Revert this once #1731 is fixed.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants