Skip to content

Incorrect coverage report with WebTest #399

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

Open
qlands opened this issue Apr 9, 2020 · 1 comment
Open

Incorrect coverage report with WebTest #399

qlands opened this issue Apr 9, 2020 · 1 comment

Comments

@qlands
Copy link

qlands commented Apr 9, 2020

As described in StackOverflow I have simple WebApp that I am testing with WebTest but the coverage result report missed lines that are executed. This might be related to #117
My test file is very simple:

class FunctionalTests(unittest.TestCase):
    def setUp(self):
        from test_app import main        
        app = main({})
        from webtest import TestApp

        self.testapp = TestApp(app)


    def test_not_found(self):
        self.testapp.get("/not_found", status=404)

The view code is:

@notfound_view_config(renderer="../templates/404.jinja2")
    def notfound_view(request):
        request.response.status = 404 # This is line 6
        return {}  # This is line 7

The coverage result is:

     Name                                                    Stmts   Miss Branch BrPart  Cover   Missing
      test_app/views/notfound.py                                 4      2      0      0    50%   6-7

But those lines are executed
Im using python3 with:

This is pytest version 5.4.1, imported from /home/cquiros/data/projects2017/personal/software/env_formshare/lib/python3.6/site-packages/pytest/__init__.py
setuptools registered plugins:
  celery-4.4.2 at /home/cquiros/data/projects2017/personal/software/env_formshare/lib/python3.6/site-packages/celery/contrib/pytest.py
  pytest-pyramid-server-1.7.0 at /home/cquiros/data/projects2017/personal/software/env_formshare/lib/python3.6/site-packages/pytest_pyramid_server.py
  pytest-shutil-1.7.0 at /home/cquiros/data/projects2017/personal/software/env_formshare/lib/python3.6/site-packages/pytest_shutil/workspace.py
  pytest-cov-2.8.1 at /home/cquiros/data/projects2017/personal/software/env_formshare/lib/python3.6/site-packages/pytest_cov/plugin.py
  pytest-webdriver-1.7.0 at /home/cquiros/data/projects2017/personal/software/env_formshare/lib/python3.6/site-packages/pytest_webdriver.py
  pytest-server-fixtures-1.7.0 at /home/cquiros/data/projects2017/personal/software/env_formshare/lib/python3.6/site-packages/pytest_server_fixtures/httpd.py
  pytest-server-fixtures-1.7.0 at /home/cquiros/data/projects2017/personal/software/env_formshare/lib/python3.6/site-packages/pytest_server_fixtures/jenkins.py
  pytest-server-fixtures-1.7.0 at /home/cquiros/data/projects2017/personal/software/env_formshare/lib/python3.6/site-packages/pytest_server_fixtures/mongo.py
  pytest-server-fixtures-1.7.0 at /home/cquiros/data/projects2017/personal/software/env_formshare/lib/python3.6/site-packages/pytest_server_fixtures/postgres.py
  pytest-server-fixtures-1.7.0 at /home/cquiros/data/projects2017/personal/software/env_formshare/lib/python3.6/site-packages/pytest_server_fixtures/redis.py
  pytest-server-fixtures-1.7.0 at /home/cquiros/data/projects2017/personal/software/env_formshare/lib/python3.6/site-packages/pytest_server_fixtures/rethink.py
  pytest-server-fixtures-1.7.0 at /home/cquiros/data/projects2017/personal/software/env_formshare/lib/python3.6/site-packages/pytest_server_fixtures/s3.py
  pytest-server-fixtures-1.7.0 at /home/cquiros/data/projects2017/personal/software/env_formshare/lib/python3.6/site-packages/pytest_server_fixtures/xvfb.py
@ionelmc
Copy link
Member

ionelmc commented May 10, 2020

Perhaps you're installing the code in site-packages and the report runs on whatever you have in CWD? Post your project layout and coveragerc.

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