Exemple #1
0
def test_import_module_by_string():
    with pytest.raises(ImportError):
        import_string('not_existing')
    m = import_string('.mod', 'pkg')
    assert isinstance(m, types.ModuleType)
    assert m.__name__ == 'pkg.mod'
Exemple #2
0
def test_import_object_by_string():
    answer = import_string('pkg.mod:answer')
    assert answer == 42
    widget = import_string('.mod:Widget', 'pkg')
    assert isinstance(widget, type)
    assert widget.__module__ == 'pkg.mod'
Exemple #3
0
def test_import_default():
    m = import_string('not_existing', default=None)
    assert m is None
Exemple #4
0
 def init_app(self, app):
     package = get_nearest_package_name(app.import_name)
     func = import_string(self._path, package=package)
     func(app)