question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Errors when using FlaskIntegration with pytest-flask

See original GitHub issue

Version 0.6.3 introduced a couple of errors when running tests for Flask based project.

First case:

― ERROR at teardown of TestResource.test_one ―
                                                                                                            
tp = <class 'AssertionError'>, value = None, tb = None                                                                                                                                                                                                                            
                                                         
    def reraise(tp, value, tb=None):                                                                                                                                                                                                                                             
        try:      
            if value is None:                                                
                value = tp()                                                                  
            if value.__traceback__ is not tb:                                                                                                                                                                                                                                    
                raise value.with_traceback(tb)                                              
>           raise value                                                
                                                                                            
../../.virtualenvs/myproject/lib/python3.6/site-packages/six.py:693:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
../../.virtualenvs/myproject/lib/python3.6/site-packages/six.py:693: in reraise
    raise value                                                                                                                                                                                                                                                                  
../../.virtualenvs/myproject/lib/python3.6/site-packages/six.py:693: in reraise
    raise value                                                                                                        
../../.virtualenvs/myproject/lib/python3.6/site-packages/pytest_flask/plugin.py:124: in teardown
    ctx.pop()                                                                                                                                                                                                                                                                    
../../.virtualenvs/myproject/lib/python3.6/site-packages/flask/ctx.py:423: in pop               
    app_ctx.pop(exc)                                                                                
../../.virtualenvs/myproject/lib/python3.6/site-packages/flask/ctx.py:231: in pop                                                                                                                                                                                       
    self.app.do_teardown_appcontext(exc)                                                                          
../../.virtualenvs/myproject/lib/python3.6/site-packages/flask/app.py:2167: in do_teardown_appcontext
    appcontext_tearing_down.send(self, exc=exc)                        
../../.virtualenvs/myproject/lib/python3.6/site-packages/blinker/base.py:267: in send                
    for receiver in self.receivers_for(sender)]
../../.virtualenvs/myproject/lib/python3.6/site-packages/blinker/base.py:267: in <listcomp>
    for receiver in self.receivers_for(sender)]
../../.virtualenvs/myproject/lib/python3.6/site-packages/sentry_sdk/integrations/flask.py:72: in _pop_appctx
    hub.pop_scope_unsafe()
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _

self = <sentry_sdk.hub.Hub object at 0x7f834f613cf8>

    def pop_scope_unsafe(self):
        """Pops a scope layer from the stack. Try to use the context manager
        `push_scope()` instead."""
        rv = self._stack.pop()
>       assert self._stack, "stack must have at least one layer"
E       AssertionError: stack must have at least one layer

../../.virtualenvs/myproject/lib/python3.6/site-packages/sentry_sdk/hub.py:321: AssertionError

Second case:

― ERROR at setup of TestResource.test_two ―
                                             
request = <SubRequest '_push_request_context' for <Function 'test_two'>>
                                                                             
    @pytest.fixture(autouse=True)                                             
    def _push_request_context(request):                                      
        """During tests execution request context has been pushed, e.g. `url_for`,
        `session`, etc. can be used in tests as is::
                                                             
            def test_app(app, client):
                assert client.get(url_for('myview')).status_code == 200
                  
        """
        if 'app' not in request.fixturenames:                                                 
            return                                                                                                                                                                                                                                                               
                                                                                            
        app = getfixturevalue(request, 'app')
                                                                                            
        # Get application bound to the live server if ``live_server`` fixture
        # is applied. Live server application has an explicit ``SERVER_NAME``,                 
        # so ``url_for`` function generates a complete URL for endpoint which
        # includes application port as well.
        if 'live_server' in request.fixturenames:
            app = getfixturevalue(request, 'live_server').app
    
        ctx = app.test_request_context()
>       ctx.push()

../../.virtualenvs/myproject/lib/python3.6/site-packages/pytest_flask/plugin.py:121:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
../../.virtualenvs/myproject/lib/python3.6/site-packages/flask/ctx.py:360: in push
    app_ctx.push()
../../.virtualenvs/myproject/lib/python3.6/site-packages/flask/ctx.py:222: in push
    appcontext_pushed.send(self.app)
../../.virtualenvs/myproject/lib/python3.6/site-packages/blinker/base.py:267: in send
    for receiver in self.receivers_for(sender)]
../../.virtualenvs/myproject/lib/python3.6/site-packages/blinker/base.py:267: in <listcomp>
    for receiver in self.receivers_for(sender)]
../../.virtualenvs/myproject/lib/python3.6/site-packages/sentry_sdk/integrations/flask.py:61: in _push_appctx
    if hub.get_integration(FlaskIntegration) is not None:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _

self = <sentry_sdk.hub.Hub object at 0x7f834f613cf8>, name_or_class = 'flask'

    def get_integration(self, name_or_class):
        """Returns the integration for this hub by name or class.  If there
        is no client bound or the client does not have that integration
        then `None` is returned.
    
        If the return value is not `None` the hub is guaranteed to have a
        client attached.
        """
        if not isinstance(name_or_class, string_types):
            name_or_class = name_or_class.identifier
>       client = self._stack[-1][0]
E       IndexError: list index out of range

../../.virtualenvs/myproject/lib/python3.6/site-packages/sentry_sdk/hub.py:175: IndexError

Issue Analytics

  • State:closed
  • Created 5 years ago
  • Comments:7 (5 by maintainers)

github_iconTop GitHub Comments

1reaction
untitakercommented, Dec 19, 2018

0.6.4 should fix this

1reaction
untitakercommented, Dec 19, 2018

master should fix this. Could you try?

pip install git+https://github.com/getsentry/sentry-python#egg=sentry-sdk

Read more comments on GitHub >

github_iconTop Results From Across the Web

Pytest errors with flask - python - Stack Overflow
I managed to fix the problem, the solution was to pass app to test_invalid_link: def test_invalid_link(self, app): """Invalid link""" form ...
Read more >
How to Report Errors in Flask Web Apps with Sentry
Learn how to use Sentry and the Flask integration to easily report errors in your Python-based web applications.
Read more >
A Set Of Pytest Fixtures to Test Flask Applications - Morioh
In this tutorial, we will share a repository of Pytest Flask: A Set Of Pytest Fixtures to Test Flask Applications. An extension of...
Read more >
Testing Flask Applications with Pytest - TestDriven.io
This test checks that a POST request to the '/' URL results in an error code of 405 (Method Not Allowed) being returned....
Read more >
Flask - Sentry Documentation
Sentry's Flask integration enables automatic reporting of errors and exceptions. Our Python SDK will install the Flask integration for all of your apps....
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found