json
06/16/2022, 3:01 PM./tests
directory I added a pact_provider
directory to projects which are pact providers and a pact_consumer
directory to projects that are pact consumers, with the idea being that the pytest tests which generate the contract live inside the pact_consumer
directory and the start-up logic for running the server in pact-verification mode lives in pact_provider
. (As best as I can tell, FastAPI needs a separate starting point to run the provider server in "pact-mode" because it has to add an extra router to define the "/_pact/provider_states"
endpoint, via this example).
We use poetry to manage dependencies and run the code, so in our pyproject.toml
alongside the start = "<app_name>.run:start"
script, I'm defining start_pact_verifier = "tests.pact_provider.setup:run"
. So in order to implement this solution, a developer has to add:
⢠the start_pact_verifier
script line to their pyproject.toml
⢠the ./tests/pact_provider/setup.py
file with a run method which imports the main application's FastAPI
instance and adds the pact states router to it
⢠the new pact states router itself, including the mapping of state strings to setup functions
⢠plus the setup functions themselves
It just seems like a lot to ask a developer to understand, and I was wondering if anyone had any tips to simplify it. Is there a way I could maybe utilize an internal poetry library to hide a lot of this boiler-plate away from the developer trying to implement this? Or maybe just a better design pattern I could be taking advantage of? My architect recommended moving the run
function to the <app_name>/run.py
module, but that seems like a pretty small step.Mike Geeves
06/16/2022, 8:44 PMjson
06/16/2022, 8:47 PMMike Geeves
06/16/2022, 8:49 PMMike Geeves
06/16/2022, 8:49 PMjson
06/16/2022, 8:50 PMjson
06/16/2022, 8:51 PMjson
06/16/2022, 8:51 PMMike Geeves
06/16/2022, 8:54 PMMike Geeves
06/16/2022, 8:56 PMMike Geeves
06/16/2022, 8:58 PMjson
06/16/2022, 8:59 PMMike Geeves
06/16/2022, 9:02 PM