Hey folks! I've been sort of just dipping my toe i...
# pact-python
j
Hey folks! I've been sort of just dipping my toe into the pact-python examples and was wondering why the pact fixture is registering stop_service with atexit and using a fixture to call stop_service after the test session is done? Isn't this redundant?
m
imo you want to have the atexit to handle if you kill it uncleanly, to avoid the port being left open if you only have the atexit then the clean handling of stopping the service and pushing to the broker won't happen because it's too late, at the exit
pretty sure I verified Bad Things happened with only atexit but let me know if that's not the case 🙂
j
I thought I read that atexit doesn't work if you kill the program
The functions registered via this module are not called when the program is killed by a signal not handled by Python, when a Python fatal internal error is detected, or when
os._exit()
is called.
https://docs.python.org/3/library/atexit.html
m
fair enough with a kill -9
but if you're having exceptions raised etc that stops the flow
j
I think pytest will always run the cleanup if there is an error in the test though, won't it? At least, by design
It seems it doesn't if the error was within the fixture itself, but even then it'll still run the cleanup of any other fixture which it has finished setting up
m
perhaps try it 🙂
👍 1
examples are in progress, so they've been cleaned up a bit but there are probably extra bits not needed that may have been preferred previously etc
*always in progress 🙂
j
Oh sure. I'm fairly new to pytest fixtures anyways, so maybe I'm misunderstanding something. I actually learned about them just to understand the pact-python examples, ha
👍 1
m
always more to learn for sure! 🙂
j
I like them a lot though, the design lends itself well to an inversion-of-control style of test setup
🙌 1
m
glad to hear that 🙂
the approach of shared fixtures was new for me 🙂 it's a little hacky but works pretty nicely
j
Yeah, I might actually make the scope of the Pact fixture "package" instead of "session" and namespace my tests based on provider so I am automatically creating a new pact for each provider which my consumer has pacts with. Yay dependency injection!
m
🤔 that would make sense I think, simple examples are always fine until you try to do the next step 😂
👍 1