https://prefect.io logo
Title
k

Kevin McCraney

11/30/2022, 8:15 PM
Hey folks, my teammates and I are trying to migrate a monorepo of tasks & flows from Prefect 1 to Prefect 2. As part of that, we're naturally doing some testing. We were previously using the
is_successful()
method in an assert in our testing, and to move that to Prefect 2, we were thinking we might call
get_run_context()
to get the flow run state and return some value (likely 'Completed' from the
state_name
parameter). We've observed that calling
get_run_context()
within a flow's context causes the flow to hang. Has anyone observed this, or does anyone have any suggestions for remedy?
z

Zanie

11/30/2022, 8:35 PM
That’s really weird! Calling
get_run_context
should never hang. If you share a MRE that’d be helpful.
That said, you shouldn’t need to access the run context for testing — what are you trying to do?
k

Kevin McCraney

11/30/2022, 8:47 PM
thanks for your response @Zanie. If you let me know what "MRE" stands for, I would be happy to share one
z

Zanie

11/30/2022, 8:52 PM
Minimal reproducible example 🙂
k

Kevin McCraney

11/30/2022, 8:55 PM
thanks much!
I figured out a way around what I wanted to do, but it does raise another question about flow name behavior. I have a named flow that I am spinning up in pytest, When I run my collection of tests, I get a warning that says:
UserWarning: A flow named 'double-quote-cleanup-flow' and defined at XXX_location conflicts with another flow. Consider specifying a unique `name` parameter in the flow definition:
  
   `@flow(name='my_unique_name', ...)`
    warnings.warn(

-- Docs: <https://docs.pytest.org/en/stable/how-to/capture-warnings.html>
I've added a uuid to the flow name so it's different every runtime, and that suppresses the error. Is there a suggested way of deregistering flows if they're called in a test suite?
z

Zanie

11/30/2022, 10:30 PM
Yeah we reset the registry after every test internally. It's in our conftest file, I can link when I'm back at my laptop.
k

Kevin McCraney

11/30/2022, 10:30 PM
no worries michael! thanks 😄