<@ULVA73B9P> - tests/ingestion/connector/jira/clou...
# ask-marvin
j
@Marvin - tests/ingestion/connector/jira/cloud/pipeline/test_jira_worker_delta_integration.py:TestProjectsWorkerDelta:test_projects_worker_writes_correct_rows tests/ingestion/connector/jira/cloud/pipeline/test_jira_worker_delta_integration.py:TestIssuesWorkerDelta:test_issues_worker_writes_correct_rows tests/ingestion/connector/jira/cloud/pipeline/test_jira_worker_delta_integration.py:TestIssuesWorkerDelta:test_issues_worker_idempotent_same_fixture tests/ingestion/connector/jira/cloud/pipeline/test_jira_worker_delta_integration.py:TestIssuesWorkerDelta:test_issues_worker_upsert_on_overlap tests/ingestion/connector/jira/cloud/pipeline/test_jira_worker_delta_integration.py:TestChangelogsWorkerDelta:test_changelogs_worker_writes_correct_rows /Users/josephwibowo/programming/github/ingestion-service/.venv/lib/python3.12/site-packages/prefect/artifacts.py106 FutureWarning: Artifact creation outside of a flow or task run is deprecated and will be removed in a later version. warnings.warn( how can we prevent this artifact code from running in unit tests
m
thought for 181.7 seconds
It looks like your tests are importing code that calls Prefect’s artifact helpers outside a flow/task run, which triggers this FutureWarning in Prefect 3.x. You have a few good options depending on whether you want to truly prevent artifact creation in tests or just silence the warning. Quick clarification: do you want to fully skip artifact creation during tests, or is silencing the warning acceptable? Below are options for both. Options to prevent artifact code from running in tests 1) Add a guard around artifact creation (recommended for production code) Wrap your artifact calls so they only run inside a Prefect run context. This prevents execution in unit tests and future-proofs you for when Prefect removes support for out-of-context artifact creation.
Copy code
import os
from prefect.context import get_run_context, MissingContextError
from prefect.artifacts import create_link_artifact

def create_link_artifact_if_in_context(*, link: str, key: str):
    # Optional test toggle
    if os.getenv("DISABLE_PREFECT_ARTIFACTS") == "1":
        return None
    try:
        get_run_context()
    except MissingContextError:
        return None
    return create_link_artifact(link=link, key=key)
In tests, set
DISABLE_PREFECT_ARTIFACTS=1
or just rely on the context check. 2) Monkeypatch artifact functions to no-ops in pytest If you want to prevent any artifact code from running in tests without touching production code:
Copy code
# conftest.py
import pytest
import prefect.artifacts as pa

def _noop(*args, **kwargs):
    return None

async def _anoop(*args, **kwargs):
    return None

@pytest.fixture(autouse=True)
def disable_prefect_artifacts(monkeypatch):
    # Patch all artifact helpers to no-ops
    names = [
        "create_link_artifact", "acreate_link_artifact",
        "create_markdown_artifact", "acreate_markdown_artifact",
        "create_table_artifact", "acreate_table_artifact",
        "create_progress_artifact", "acreate_progress_artifact",
        "update_progress_artifact", "aupdate_progress_artifact",
        "create_image_artifact", "acreate_image_artifact",
    ]
    for name in names:
        if hasattr(pa, name):
            monkeypatch.setattr(pa, name, _anoop if name.startswith("a") else _noop)
This completely prevents artifact creation during tests. If you only need to silence the warning 3) Filter the specific warning in pytest config
Copy code
# pytest.ini or pyproject.toml [tool.pytest.ini_options]
filterwarnings =
    ignore:Artifact creation outside of a flow or task run is deprecated:FutureWarning
4) Wrap the call in tests with pytest.warns When your test intentionally triggers out-of-context creation:
Copy code
import pytest
from prefect.artifacts import create_link_artifact

def test_artifact_outside_context():
    with pytest.warns(FutureWarning):
        create_link_artifact(link="<https://example.com>", key="k")
Notes - There is no Prefect setting/env var that globally disables artifact creation. You’ll need to guard, patch, or filter as above. - Best practice in Prefect 3.x is to only create artifacts inside flows/tasks. Refs: - Artifacts concept: Artifacts (Prefect docs) - Run context API: get_run_context