test_doit_targets.py 709 B

1234567891011121314151617181920212223242526
  1. import pytest
  2. from doit.doit_cmd import DoitMain
  3. from src.faostat_data_primap.helper.paths import root_path
  4. @pytest.fixture
  5. def change_to_project_root(monkeypatch):
  6. monkeypatch.chdir(root_path)
  7. def test_doit_command(change_to_project_root, tmp_path):
  8. """
  9. Test a `doit` task programmatically.
  10. """
  11. # save_path = tmp_path
  12. # save_path.mkdir()
  13. # Command-line arguments for the doit task
  14. cmd_args = ["run", "read_data", f"save_path={tmp_path!s}", "run_id=2025"]
  15. # Run the doit command programmatically
  16. result = DoitMain().run(cmd_args)
  17. # Assert that the task ran successfully (return code 0)
  18. assert result == 0, f"doit task failed with return code: {result}"