Write a Python flow project whose `kickoff` script lives in `main.py`, and run from it inside its env (as `uv run crewai run` would).
(tmp_path, monkeypatch)
| 1416 | |
| 1417 | @pytest.fixture |
| 1418 | def python_flow_project(tmp_path, monkeypatch): |
| 1419 | """Write a Python flow project whose `kickoff` script lives in `main.py`, |
| 1420 | and run from it inside its env (as `uv run crewai run` would).""" |
| 1421 | package = f"inputs_probe_{tmp_path.name.replace('-', '_')}" |
| 1422 | |
| 1423 | def write(main_py: str, *, kickoff_script: bool = True) -> Path: |
| 1424 | scripts = f'[project.scripts]\nkickoff = "{package}.main:kickoff"\n' |
| 1425 | (tmp_path / "pyproject.toml").write_text( |
| 1426 | f'[project]\nname = "{package}"\n' |
| 1427 | + (scripts if kickoff_script else "") |
| 1428 | + '[tool.crewai]\ntype = "flow"\n' |
| 1429 | ) |
| 1430 | source = tmp_path / "src" / package |
| 1431 | source.mkdir(parents=True) |
| 1432 | (source / "__init__.py").write_text("") |
| 1433 | (source / "main.py").write_text(main_py) |
| 1434 | return tmp_path |
| 1435 | |
| 1436 | monkeypatch.chdir(tmp_path) |
| 1437 | monkeypatch.setenv("UV_RUN_RECURSION_DEPTH", "1") |
| 1438 | monkeypatch.setenv("CREWAI_TRACING_ENABLED", "false") |
| 1439 | yield write |
| 1440 | for name in [m for m in sys.modules if m.split(".")[0] == package]: |
| 1441 | del sys.modules[name] |
| 1442 | |
| 1443 | |
| 1444 | _TWO_FLOWS = """ |
no outgoing calls
no test coverage detected