https://prefect.io logo
Title
b

Boris Tseytlin

11/24/2022, 4:28 PM
Hey guys. What’s the best practice for testing a flow that uses blocks? I am creating a block with credentials for a test minio storage and running
.save
on it, but when I try to retrieve it later by
load
I get error 404 from Prefect.
ValueError: Unable to find block document named test-minio-url for block type string
@pytest.fixture(autouse=True, scope="session")
def prefect_test_fixture():
    with prefect_test_harness():
        yield


@pytest.fixture(scope="session")
def minio_blocks(prefect_test_fixture):
    minio_creds_block = MinIOCredentials(
        minio_root_user=Config.MINIO_USER,
        minio_root_password=Config.MINIO_PASSWORD,
    )
    minio_creds_block.save("test-minio-creds")
    minio_url_block = String(Config.MINIO_URL)
    minio_url_block.save("test-minio-url")
    return minio_creds_block, minio_url_block


@pytest.fixture
def dummy_mission(minio_blocks):
    minio_creds_block, minio_url_block = minio_blocks
    minio_url = String.load(minio_url_block).value # <- ERROR HERE
    minio_url = minio_url.split("/")[-1:][0]
    minio_creds = MinIOCredentials.load(minio_creds_block)
1
r

Ryan Peden

11/24/2022, 6:58 PM
Since
minio_blocks
is returning instead of yielding, I'm not sure that
dummy_mission
is getting called inside the prefect test harness. Does it make a difference if you change the last line of
minio_blocks
to
yield minio_creds_block, minio_url_block
? I'm going to test this to verify; it's just the first thing that comes to mind.
b

Boris Tseytlin

11/24/2022, 7:00 PM
I will try!
That worked!
Thank you
👍 1