Python Forum
How to fix "'dict_values' object has no attribute 'inject_wsgi'" in session_transacti
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
How to fix "'dict_values' object has no attribute 'inject_wsgi'" in session_transacti
#1
The problem is that when running tests on GitHub Workflow, the error AttributeError: 'dict_values' object has no attribute 'inject_wsgi' occurs and tests fails, but this error does not occur when running tests locally and everything goes well.

Full log error:
    ______ ERROR at setup of test_fetch_members ______
    
        @pytest.fixture(scope="function")
        def client() -> FlaskClient:
    >       yield create_client()
    
    unittests/tests/conftest.py:33: 
    _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 
    unittests/tests/conftest.py:13: in create_client
        with client.session_transaction() as session:
    /opt/hostedtoolcache/Python/3.11.3/x64/lib/python3.11/contextlib.py:137: in __enter__
        return next(self.gen)
    _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 
    
    self = <FlaskClient <Flask 'app'>>, args = ()
    kwargs = {'environ_overrides': {}}, app = <Flask 'app'>, environ_overrides = {}
    
        @contextmanager
        def session_transaction(
            self, *args: t.Any, **kwargs: t.Any
        ) -> t.Generator[SessionMixin, None, None]:
            """When used in combination with a ``with`` statement this opens a
            session transaction.  This can be used to modify the session that
            the test client uses.  Once the ``with`` block is left the session is
            stored back.
        
            ::
        
                with client.session_transaction() as session:
                    session['value'] = 42
        
            Internally this is implemented by going through a temporary test
            request context and since session handling could depend on
            request variables this function accepts the same arguments as
            :meth:`~flask.Flask.test_request_context` which are directly
            passed through.
            """
            if self.cookie_jar is None:
                raise RuntimeError(
                    "Session transactions only make sense with cookies enabled."
                )
            app = self.application
            environ_overrides = kwargs.setdefault("environ_overrides", {})
    >       self.cookie_jar.inject_wsgi(environ_overrides)
    E       AttributeError: 'dict_values' object has no attribute 'inject_wsgi'
    /opt/hostedtoolcache/Python/3.11.3/x64/lib/python3.11/site-packages/flask/testing.py:146: AttributeError
conftest.py

    from flask.testing import FlaskClient
    from app import app_instance
    import pytest

    def create_client() -> FlaskClient:
        app_instance.app.config["TESTING"] = True
    
        with app_instance.test_client as client:
            with app_instance.context:
                with client.session_transaction() as session:
                    session["logged_in"] = True
            return client
    
    
    @pytest.fixture(scope="function")
    def client() -> FlaskClient:    
        yield create_client()
app.py

    from flask.testing import FlaskClient
    from flask import Flask
    
    
    class App:
        def __init__(self):
            self.app = Flask(__name__)
    
        def run(self, **args):
            self.app.run(**args)
    
        @property
        def test_client(self) -> FlaskClient:
            return self.app.test_client()
    
        @property
        def context(self) -> FlaskClient:
            return self.app.app_context()
    
        @property
        def flask_app(self) -> Flask:
            return self.app
    
    app_instance = App()
GitHub Workflow:
    name: Python application
    
    on:
      push:
        branches: [ "master" ]
      pull_request:
        branches: [ "master" ]
    
    permissions:
      contents: read
    
    jobs:
      build:
        runs-on: ubuntu-latest
    
        steps:
        - uses: actions/checkout@v3
        - name: Set up Python 3.11.3
          uses: actions/setup-python@v3
          with:
            python-version: "3.11.3"
    
        - name: Install dependencies
          run: |
            python -m pip install --upgrade pip
            pip install -r requirements.txt
    
        - name: Test with pytest
          run: |
            pytest
I hope for your help in trying to figure out why this error occurs on GitHub.
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  AttributeError: 'ellipsis' object has no attribute 'register_blueprint' Mechanicalpixelz 2 2,423 Dec-29-2021, 01:30 AM
Last Post: Mechanicalpixelz
  AttributeError: ResultSet object has no attribute 'get_text' KatMac 1 4,405 May-07-2021, 05:32 PM
Last Post: snippsat
  Python 3.9 : BeautifulSoup: 'NoneType' object has no attribute 'text' fudgemasterultra 1 8,942 Mar-03-2021, 09:40 AM
Last Post: Larz60+
  'NavigableString' object has no attribute 'h2' RandomCoder 5 5,431 May-20-2020, 09:01 AM
Last Post: Larz60+
  AttributeError: 'str' object has no attribute 'xpath' nazmulfinance 4 10,512 Nov-11-2019, 05:15 PM
Last Post: nazmulfinance
  AttributeError: 'str' object has no attribute 'xpath' nazmulfinance 0 3,088 Nov-10-2019, 09:13 PM
Last Post: nazmulfinance
  form.populate_obj problem "object has no attribute translate" pascale 0 3,662 Jun-12-2019, 07:30 PM
Last Post: pascale
  Error object has no attribute text hcyeap 3 13,939 May-21-2019, 07:12 AM
Last Post: buran
  AttributeError: 'Response' object has no attribute 'replace' Truman 12 23,456 Mar-20-2019, 12:59 AM
Last Post: ichabod801
  AttributeError: 'dict' object has no attribute 'is_active' (PyMongo And Flask) usman 0 4,978 Nov-20-2018, 09:50 PM
Last Post: usman

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020