@@ -65,7 +65,7 @@ provider = Provider('my-backend-service')
6565pact = consumer.has_pact_with(provider, pact_dir = ' /path/to/pacts' )
6666(
6767 pact
68- .given(' user exists' ) # 1
68+ .given(' user exists' ) # (1)
6969 .upon_receiving(' a request for user data' )
7070 .with_request(
7171 ' GET' ,
@@ -80,12 +80,12 @@ pact = consumer.has_pact_with(provider, pact_dir='/path/to/pacts')
8080 )
8181)
8282
83- pact.start_service() # 2
83+ pact.start_service() # (2)
8484pact.setup()
8585response = requests.get(pact.uri + ' /users/123' )
8686assert response.json() == {' id' : 123 , ' name' : ' Alice' }
87- pact.verify() # 3
88- pact.stop_service() # 4
87+ pact.verify() # (3)
88+ pact.stop_service() # (4)
8989# Pact file is written as part of verify() or when the service stops
9090```
9191
@@ -102,7 +102,7 @@ pact = Pact('my-web-front-end', 'my-backend-service')
102102(
103103 pact
104104 .upon_receiving(' a request for user data' )
105- .given(' user exists' , id = 123 , name = ' Alice' ) # 1
105+ .given(' user exists' , id = 123 , name = ' Alice' ) # (1)
106106 .with_request(' GET' , ' /users/123' )
107107 .with_header(' Accept' , ' application/json' )
108108 .with_query_parameter(' include' , ' profile' )
@@ -111,10 +111,10 @@ pact = Pact('my-web-front-end', 'my-backend-service')
111111 .with_body({' id' : 123 , ' name' : ' Alice' }, content_type = ' application/json' )
112112)
113113
114- with pact.serve() as srv: # 2
114+ with pact.serve() as srv: # (2)
115115 response = requests.get(f " { srv.url} /users/123 " )
116116 assert response.json() == {' id' : 123 , ' name' : ' Alice' }
117- pact.write_file(' /path/to/pacts' ) # 3
117+ pact.write_file(' /path/to/pacts' ) # (3)
118118```
119119
1201201 . In v3, provider states can be parameterized, making it easier to reuse and manage test data across different scenarios.
0 commit comments