def test_load_flows_from_module(self, tmpdir, monkeypatch):
        monkeypatch.syspath_prepend(str(tmpdir))
        source = textwrap.dedent("""
            from prefect import Flow
            from prefect.storage import Module
            f1 = Flow("f1")
            f1.storage = Module("mymodule.submodule")
            f2 = Flow("f2")
            """)
        path = tmpdir.join("mymodule.py")
        path.write(source)

        flows = {f.name: f for f in load_flows_from_module("mymodule")}
        assert len(flows) == 2
        assert isinstance(flows["f1"].storage, Module)
        assert flows["f1"].storage.module == "mymodule.submodule"
        assert isinstance(flows["f2"].storage, Module)
        assert flows["f2"].storage.module == "mymodule"
Пример #2
0
    def test_load_flows_from_module_not_found_error(self, tmpdir, monkeypatch,
                                                    capsys):
        monkeypatch.syspath_prepend(str(tmpdir))
        tmpdir.join("mymodule1.py").ensure(file=True)
        tmpdir.join("mymodule2.py").write("raise ValueError('oh no!')")

        with pytest.raises(TerminalError, match="No module named 'mymodule3'"):
            load_flows_from_module("mymodule3")

        with pytest.raises(TerminalError, match="No module named 'mymodule3'"):
            load_flows_from_module("mymodule3.submodule")

        with pytest.raises(TerminalError,
                           match="No module named 'mymodule1.submodule'"):
            load_flows_from_module("mymodule1.submodule")

        with pytest.raises(TerminalError):
            load_flows_from_module("mymodule2")

        out, _ = capsys.readouterr()
        assert "oh no!" in out
        assert "Error loading 'mymodule2'" in out