Skip to content

Testing Flask apps breaks with 5.0.0 #5532

Closed
@aberres

Description

@aberres

I just upgraded to 5.0.0 and even the most simplistic Flask app cannot be tested anymore.

It seems as if this might be related to an issue from 2013: #317

Minimalistic test case

from flask import Flask

def test_example():
    app = Flask(__name__)
    assert True

Backtrace

planningsvc/tests/flaskjsonapi/test_a.py:5 (test_example)
def test_example():
>       app = Flask(__name__)

test_a.py:7: 
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 
/Users/berres/venv/mpptool/lib/python3.7/site-packages/flask/app.py:381: in __init__
    instance_path = self.auto_find_instance_path()
/Users/berres/venv/mpptool/lib/python3.7/site-packages/flask/app.py:678: in auto_find_instance_path
    prefix, package_path = find_package(self.import_name)
/Users/berres/venv/mpptool/lib/python3.7/site-packages/flask/helpers.py:826: in find_package
    loader, root_mod_name):
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 

loader = <_pytest.assertion.rewrite.AssertionRewritingHook object at 0x10e8c96a0>
mod_name = 'test_a'

    def _matching_loader_thinks_module_is_package(loader, mod_name):
        """Given the loader that loaded a module and the module this function
        attempts to figure out if the given module is actually a package.
        """
        # If the loader can tell us if something is a package, we can
        # directly ask the loader.
        if hasattr(loader, 'is_package'):
            return loader.is_package(mod_name)
        # importlib's namespace loaders do not have this functionality but
        # all the modules it loads are packages, so we can take advantage of
        # this information.
        elif (loader.__class__.__module__ == '_frozen_importlib' and
              loader.__class__.__name__ == 'NamespaceLoader'):
            return True
        # Otherwise we need to fail with an error that explains what went
        # wrong.
        raise AttributeError(
            ('%s.is_package() method is missing but is required by Flask of '
             'PEP 302 import hooks.  If you do not use import hooks and '
             'you encounter this error please file a bug against Flask.') %
>           loader.__class__.__name__)
E       AttributeError: AssertionRewritingHook.is_package() method is missing but is required by Flask of PEP 302 import hooks.  If you do not use import hooks and you encounter this error please file a bug against Flask.

/Users/berres/venv/mpptool/lib/python3.7/site-packages/flask/helpers.py:789: AttributeError

Metadata

Metadata

Assignees

No one assigned

    Labels

    topic: rewriterelated to the assertion rewrite mechanismtype: bugproblem that needs to be addressed

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions