:wave: Hello, team! I’ve been trying hard to find ...
# pact-python
t
👋 Hello, team! I’ve been trying hard to find an example of how to set up a Mock Service Provider to run pacts verification process without running a server in Python. I’m currently using Pactman in Consumer side, but open to change. Please point me to a good resource on how to verify pacts in unit tests. Thanks!
👋 1
m
Hi Tomasz, Pact Python requires you start your provider locally (ideally with stubbed dependencies). There’s no way around that currently that I’m aware of
t
Thank you. That is very sad.
m
Is starting the provider troublesome?
t
Yes. First it’s way slower in general and more involved, but in this situation, it’s a bunch of lambda functions.
👍 1
m
Are these lambda functions exposed via an HTTP interface or are they more of a req/res style invocation? (also, I assume when you say lambda, you mean AWS lambda?)
t
They are aws lambdas. Invoking them locally via real HTTP interface is a bit of a pain in the neck. The handlers themselves can be invoked but the HTTP interface is no longer there, as they accept specific input (event), normally created by AWS gateway from HTTP call contents, similar to what any web framework does when converting pure raw bits conforming to HTTP protocol into objects such as “req”. This part is what is missing. But also, it’s not strictly needed to interact via this interface.
👍 1
m
I understand. I don’t know Python all that well, but with NodeJS and Golang it was trivial to use SAM/Serverless to start an HTTP service with a gateway simulation for this purpose. You don’t need to start the HTTP service in this way, however it’s convenient because you know it will mimic the behaviour of the API gateway and invoke your lambda with the correct additional context (I’ve also previously created a separate HTTP interface to invoke the underlying lambda for testing purposes, which can be useful in certain situations also).
In any case, at the moment it’s a moot point because the Python library does require an HTTP target to hit.
Another option in the future could be a plugin (see docs.pact.io/plugins) which abstracts this stuff out. We have yet to roll out the rust core to Python, which is a pre-requisite for that support also. So sadly, that option is out too. We are looking for some additional maintainer support for Python, so if you’re interested in improving this situation we’d love to chat!
t
Thanks @Matt (pactflow.io / pact-js / pact-go) We have wrapped the handler code in separate Flask instance, which is indeed handy anyway which is faster to spin up - still on this 🙂
🙌 1