Open DannyCork opened 5 years ago
Sorry for the delay, Danny. Is this still an issue?
Hello @r1chardj0n3s ,
This is still an issue which is observed for my code. `import atexit import unittest import requests from pactman import Consumer, Provider, Term, Like from pactman.verifier.pytest_plugin import pact_verifier pact = Consumer('ConsumerPOC').has_pact_with(Provider('Provider'), use_mocking_server=True, pact_dir="C:\Users\*****\PycharmProjects\pact-python-master") pact.start_mocking() atexit.register(pact.stop_mocking)
class GetUserInfoContract(unittest.TestCase):
def test_generate_pact_from_consumer_end(self):
# Setting up Expected Response
expected = {'skip': 0, 'limit': 150}
# Simulating an Real HTTP Server
pact.given(
'User ML exists and is not an administrator'
).upon_receiving(
'a request for ML'
).with_request(
method='GET',
path='/api',
).will_respond_with(200, body=expected)
with pact:
result = requests.get(pact.uri + '/api')
self.assertEqual(result.json(), expected)`
When the above code is run in debug mode, I found the error 'Received but no interaction registered'. I executed requests.get(pact.uri + '/api')
explicitly during debugging and then I got to see this issue
When it is run in a single shot I am seeing below error.
requests.exceptions.ConnectionError: HTTPConnectionPool(host='localhost', port=8155): Max retries exceeded with url: /api (Caused by NewConnectionError('<urllib3.connection.HTTPConnection object at 0x04595310>: Failed to establish a new connection: [WinError 10061] No connection could be made because the target machine actively refused it'))
Any help is appreciated !!!
Thanks.
"No connection could be made because the target machine actively refused it" looks like some sort of firewall configuration issue?
But @r1chardj0n3s , If I use the below code also I am able to generate PACT.
pact = Consumer('ConsumerPOC').has_pact_with(Provider('Provider'),
use_mocking_server=False, pact_dir="C:\Users\*****\PycharmProjects\pact-python-master")
# pact.start_mocking()
# atexit.register(pact.stop_mocking)
Observe, I have commented the lines Start server and Stop server also by giving the flag value use_mocking_server=False
Then what is the actual need of previous code where in we are starting and stopping the mock server ??
Yep! You don't need to run a mocking server to get the benefits of pact mocking - it's included mostly for legacy and edge case needs.
Can you help me in understanding what do you mean by edge case needs... !!!
Any Example which can help me understand the concept more clear.
Sorry, I can't actually think of one right now. If you don't need it, then don't use it.
Okay @r1chardj0n3s .
I'm having an issue when attempting to make a request to the mock server. The mock server returns a 500 status code and a message 'received but no interaction registered'
My code looks like this:
I then run it using
and get
I have no additional code. My understanding is that pact provides the mocking, is this correct?
Any help appreciated. Thanks.