
import sys

sys.modules['redis'] = None


def test_redis_import_error():
    """Test that we can load FlaskMultiRedis even if redis module
    is not available."""

    from flask_multi_redis import FlaskMultiRedis
    f = FlaskMultiRedis()
    assert f.provider_class is None


def test_constructor_app(mocker):
    """Test that the constructor passes the app to FlaskMultiRedis.init_app."""

    from flask_multi_redis import FlaskMultiRedis
    mocker.patch.object(FlaskMultiRedis, 'init_app', autospec=True)
    app_stub = mocker.stub(name='app_stub')

    FlaskMultiRedis(app_stub)

    FlaskMultiRedis.init_app.assert_called_once_with(mocker.ANY, app_stub)


from sys import modules, version_info

if version_info >= (3,):
    from imp import reload


def test_redis_import_error():
    """Test that we can load FlaskMultiRedis even if redis module
    is not available."""

    import flask_multi_redis
    modules['redis'] = None
    flask_multi_redis = reload(flask_multi_redis)
    FlaskMultiRedis = flask_multi_redis.FlaskMultiRedis

    f = FlaskMultiRedis()
    assert f.provider_class is None


def test_constructor_app(mocker):
    """Test that the constructor passes the app to FlaskMultiRedis.init_app."""

    import flask_multi_redis
    del(modules['redis'])
    flask_multi_redis = reload(flask_multi_redis)
    FlaskMultiRedis = flask_multi_redis.FlaskMultiRedis

    mocker.patch.object(FlaskMultiRedis, 'init_app', autospec=True)
    app_stub = mocker.stub(name='app_stub')

    FlaskMultiRedis(app_stub)

    FlaskMultiRedis.init_app.assert_called_once_with(mocker.ANY, app_stub)

Update unit tests to improve redis_import_error
Update unit tests to improve redis_import_error

  
- import sys
+ from sys import modules, version_info
  
- sys.modules['redis'] = None
+ if version_info >= (3,):
+     from imp import reload
  
  
  def test_redis_import_error():
      """Test that we can load FlaskMultiRedis even if redis module
      is not available."""
  
-     from flask_multi_redis import FlaskMultiRedis
+     import flask_multi_redis
+     modules['redis'] = None
+     flask_multi_redis = reload(flask_multi_redis)
+     FlaskMultiRedis = flask_multi_redis.FlaskMultiRedis
+ 
      f = FlaskMultiRedis()
      assert f.provider_class is None
  
  
  def test_constructor_app(mocker):
      """Test that the constructor passes the app to FlaskMultiRedis.init_app."""
  
-     from flask_multi_redis import FlaskMultiRedis
+     import flask_multi_redis
+     del(modules['redis'])
+     flask_multi_redis = reload(flask_multi_redis)
+     FlaskMultiRedis = flask_multi_redis.FlaskMultiRedis
+ 
      mocker.patch.object(FlaskMultiRedis, 'init_app', autospec=True)
      app_stub = mocker.stub(name='app_stub')
  
      FlaskMultiRedis(app_stub)
  
      FlaskMultiRedis.init_app.assert_called_once_with(mocker.ANY, app_stub)
  
Update unit tests to improve redis_import_error
## Code Before:

import sys

sys.modules['redis'] = None


def test_redis_import_error():
    """Test that we can load FlaskMultiRedis even if redis module
    is not available."""

    from flask_multi_redis import FlaskMultiRedis
    f = FlaskMultiRedis()
    assert f.provider_class is None


def test_constructor_app(mocker):
    """Test that the constructor passes the app to FlaskMultiRedis.init_app."""

    from flask_multi_redis import FlaskMultiRedis
    mocker.patch.object(FlaskMultiRedis, 'init_app', autospec=True)
    app_stub = mocker.stub(name='app_stub')

    FlaskMultiRedis(app_stub)

    FlaskMultiRedis.init_app.assert_called_once_with(mocker.ANY, app_stub)

## Instruction:
Update unit tests to improve redis_import_error
## Code After:

from sys import modules, version_info

if version_info >= (3,):
    from imp import reload


def test_redis_import_error():
    """Test that we can load FlaskMultiRedis even if redis module
    is not available."""

    import flask_multi_redis
    modules['redis'] = None
    flask_multi_redis = reload(flask_multi_redis)
    FlaskMultiRedis = flask_multi_redis.FlaskMultiRedis

    f = FlaskMultiRedis()
    assert f.provider_class is None


def test_constructor_app(mocker):
    """Test that the constructor passes the app to FlaskMultiRedis.init_app."""

    import flask_multi_redis
    del(modules['redis'])
    flask_multi_redis = reload(flask_multi_redis)
    FlaskMultiRedis = flask_multi_redis.FlaskMultiRedis

    mocker.patch.object(FlaskMultiRedis, 'init_app', autospec=True)
    app_stub = mocker.stub(name='app_stub')

    FlaskMultiRedis(app_stub)

    FlaskMultiRedis.init_app.assert_called_once_with(mocker.ANY, app_stub)
