def test_meta_path_loader_without_is_package(request, modules_tmpdir): app = modules_tmpdir.join('unimportable.py') app.write('import flask\napp = flask.Flask(__name__)') class Loader(object): def find_module(self, name, path=None): return self sys.meta_path.append(Loader()) request.addfinalizer(sys.meta_path.pop) with pytest.raises(AttributeError): import unimportable