Skip to content

Commit a8a07d4

Browse files
committed
docs(examples): changed provider example to use atexit
1 parent 186f4f4 commit a8a07d4

File tree

1 file changed

+8
-23
lines changed

1 file changed

+8
-23
lines changed

examples/e2e/tests/provider/test_provider.py

Lines changed: 8 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -1,29 +1,13 @@
1-
2-
# VERSION=$1
3-
# if [ -x $VERSION ]; then
4-
# echo "ERROR: You must specify a provider version"
5-
# exit
6-
# fi
7-
8-
# pipenv run pact-verifier --provider-base-url=http://localhost:5001 \
9-
# --pact-url="http://127.0.0.1/pacts/provider/UserService/consumer/UserServiceClient/latest" \
10-
# --provider-states-setup-url=http://localhost:5001/_pact/provider_states \
11-
# --provider-app-version $VERSION \
12-
# --pact-broker-username pactbroker \
13-
# --pact-broker-password pactbroker \
14-
# --publish-verification-results
15-
16-
171
"""pact test for user service client"""
182

193
import logging
204
import os
5+
import atexit
216

227
import pytest
238
from multiprocessing import Process
249

2510
from pact import Verifier
26-
2711
from pact_provider import app
2812

2913
log = logging.getLogger(__name__)
@@ -49,15 +33,16 @@
4933
def provider():
5034
print('start flask')
5135
server = Process(target=app.run, kwargs={'port': PACT_MOCK_PORT})
36+
server.start()
37+
atexit.register(stop_flask, server)
5238

53-
try:
54-
server.start()
39+
yield
5540

56-
yield
57-
finally:
58-
print('end flask')
59-
server.terminate()
41+
stop_flask(server_process=server)
6042

43+
def stop_flask(server_process: Process):
44+
print('stop flask called')
45+
server_process.terminate()
6146

6247
def test_get_user_non_admin(provider):
6348
verifier = Verifier(provider='UserService',

0 commit comments

Comments
 (0)