<@ULVA73B9P> Hey team, I ran into an issue while...
# ask-marvin
n
@Marvin Hey team, I ran into an issue while writing unit tests for Prefect 2.7.7 Ideally, we would be able to test a Prefect flow without Prefect trying to contact the server to start flows or tasks. We use the
pytest
module, and the way to fake the Prefect server during unit tests is described here.
When I use that code with Prefect 2.7.7, I get this error:
Copy code
E       TypeError: AsyncClient.__init__() got an unexpected keyword argument 'app'
Copy code
../env/lib/python3.10/site-packages/prefect/client/orion.py:183: TypeError
_This error disappears after I remove the code mentioning the
prefect_test_harness
, and start the prefect server. I can see in the Prefect UI that flows and tasks were created for the unit test. I don't think that's desirable; we would like to run unit tests in CI without the need for a prefect server._ _The other way I can get that code to run, is to stop the prefect server, enable the code using the
prefect_test_harness
, and create a new virtual env with prefect 2.20.16. In that case, the tests run as expected._ It seems to me that the dated Prefect version is to blame. Is there any way we can do this in prefect 2.7.7 or do we need toi upgrade to the latest prefect version ? orion-docs.prefect.io Testing - Prefect 2 - Coordinating the world's dataflows Learn about writing tests for Prefect flows and tasks.
m
It seems that the issue you're experiencing with the
AsyncClient
and
prefect_test_harness
in Prefect 2.7.7 is related to compatibility problems with the underlying libraries or Prefect's own implementation at that version. The error message indicates that there's an unexpected keyword argument 'app' being passed to
AsyncClient.__init__()
, which is likely due to a mismatch in the expected parameters for the
httpx.AsyncClient
. The
prefect_test_harness
is designed to allow testing without connecting to a Prefect server by using a temporary local SQLite database. However, the error you're encountering suggests that there might be a bug or incompatibility in that specific version (2.7.7). Options to Resolve the Issue: 1. Upgrade Prefect: As you noted, upgrading to a more recent version of Prefect (like 2.20.16) resolves the issue. This is likely because the newer version has fixed the compatibility problems or updated the dependencies. 2. Review the Code: Ensure that the code for setting up the
prefect_test_harness
is exactly as specified in the Prefect 2.x testing guide. Any deviation might cause unexpected errors. 3. Check Dependencies: Verify that all dependencies, especially
httpx
, are compatible with Prefect 2.7.7. Sometimes, updating Prefect might also require updating related libraries. 4. Use Latest Testing Practices: Follow the latest practices for testing Prefect flows, as outlined in the Prefect documentation. This might involve changes in how fixtures or context managers are used. Given the information, upgrading to the latest version seems to be the most straightforward solution, especially if you're planning to run these tests in a CI environment without a Prefect server. If you decide to stick with 2.7.7, you might need to explore the specific configurations of
httpx
or any patches that might be applicable to address the issue with
AsyncClient
.
n
where can i explore the specific configuration of hhtpx ? @Marvin
m
To explore the specific configuration of
httpx
, you can refer to the official httpx documentation. This documentation provides detailed information on how to configure and use
httpx
, including the
AsyncClient
class and its parameters. Here are some key sections you might find useful: - Quickstart: For an overview of basic usage. - Advanced Usage: For detailed configuration options, including custom transports and connection pooling. - API Reference: For detailed information on classes, methods, and parameters, including
AsyncClient
. By reviewing these sections, you can gain a better understanding of how to configure
httpx
to fit your needs, especially if you're encountering compatibility issues with Prefect.