Skip to content

Instantly share code, notes, and snippets.

@singingwolfboy
Last active July 3, 2019 07:43
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save singingwolfboy/5f57bccc293cbf8f352dbaea6d7ee537 to your computer and use it in GitHub Desktop.
Save singingwolfboy/5f57bccc293cbf8f352dbaea6d7ee537 to your computer and use it in GitHub Desktop.
Minimal test case for Pytest 5 failure with Flask.
import flask
def test_pytest_failure():
"""
This test passes on Pytest 4, but throws an error on Pytest 5.
"""
app = flask.Flask(__name__)
$ pytest test_pytest_failure.py
============================= test session starts ==============================
platform darwin -- Python 3.7.3, pytest-5.0.0, py-1.8.0, pluggy-0.12.0
rootdir: /private/tmp
collected 1 item
test_pytest_failure.py F [100%]
=================================== FAILURES ===================================
_____________________________ test_pytest_failure ______________________________
def test_pytest_failure():
"""
This test passes on Pytest 4, but throws an error on Pytest 5.
"""
> app = flask.Flask(__name__)
test_pytest_failure.py:7:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
/Users/singingwolfboy/.virtualenvs/tmp/lib/python3.7/site-packages/flask/app.py:381: in __init__
instance_path = self.auto_find_instance_path()
/Users/singingwolfboy/.virtualenvs/tmp/lib/python3.7/site-packages/flask/app.py:678: in auto_find_instance_path
prefix, package_path = find_package(self.import_name)
/Users/singingwolfboy/.virtualenvs/tmp/lib/python3.7/site-packages/flask/helpers.py:826: in find_package
loader, root_mod_name):
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
loader = <_pytest.assertion.rewrite.AssertionRewritingHook object at 0x10fb42208>
mod_name = 'test_pytest_failure'
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/singingwolfboy/.virtualenvs/tmp/lib/python3.7/site-packages/flask/helpers.py:789: AttributeError
=============================== warnings summary ===============================
/Users/singingwolfboy/.virtualenvs/tmp/lib/python3.7/site-packages/jinja2/utils.py:485
/Users/singingwolfboy/.virtualenvs/tmp/lib/python3.7/site-packages/jinja2/utils.py:485: DeprecationWarning: Using or importing the ABCs from 'collections' instead of from 'collections.abc' is deprecated, and in 3.8 it will stop working
from collections import MutableMapping
/Users/singingwolfboy/.virtualenvs/tmp/lib/python3.7/site-packages/jinja2/runtime.py:318
/Users/singingwolfboy/.virtualenvs/tmp/lib/python3.7/site-packages/jinja2/runtime.py:318: DeprecationWarning: Using or importing the ABCs from 'collections' instead of from 'collections.abc' is deprecated, and in 3.8 it will stop working
from collections import Mapping
-- Docs: https://docs.pytest.org/en/latest/warnings.html
===================== 1 failed, 2 warnings in 0.22 seconds =====================
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment