https://pact.io logo
Join Slack
Powered by
# pact-python
  • a

    Aaron Swerlein

    01/09/2023, 2:44 PM
    Hey team. I am trying to create provider side validations in a separate python repo (consumer written in Ruby framework). I am trying to find good documentation on provider states in python, but I am not having much luck. I found the pact-python repo on Github, but am not having luck with creating a port to send the requests to. Whenever I run the
    pact-verifier
    command, it says connection refused on the port
  • g

    GitHub

    01/17/2023, 11:51 PM
    1 new commit pushed to
    <https://github.com/pact-foundation/pact-python/tree/master|master>
    by bethesque
    <https://github.com/pact-foundation/pact-python/commit/53ca129dbee544c6e43ce4c01d8a238e9c0c1ac6|53ca129d>
    - chore: add workflow to create a jira issue for pactflow team when smartbear-supported label added to github issue pact-foundation/pact-python
  • b

    Bram Hautekiet

    01/22/2023, 11:00 PM
    Hi folks, we're experimenting with a Pact POC for our python microservices. More specifically we are trying to run the verification for the provider against a flask test_client instead of against a live server, but this seems not possible (yet)? The flask test client makes requests to the application without running a live server. You can test the client programmatically by calling
    response = test_client.get()
    ,
    response = <http://test_client.post|test_client.post>()
    , ... Using this test client has some advantages compared to running a local server: it's faster, it makes it easier to mock dependent services (like databases), it makes it very easy to deal with authentication etc... But as far as I can see the only way of verifying a provider contract is with the standalone pact-verifier tool (or a wrapper around the tool), where you need to pass a provider-base-url which points to a live server?
    m
    • 2
    • 1
  • g

    GitHub

    01/24/2023, 5:04 PM
    1 new commit pushed to
    <https://github.com/pact-foundation/pact-python/tree/master|master>
    by elliottmurray
    <https://github.com/pact-foundation/pact-python/commit/1bbdd37aeb16993af124e386c3d1d8b96b656f81|1bbdd37a>
    - feat: Enhance provider states for pact-message (#322) pact-foundation/pact-python
  • g

    GitHub

    01/24/2023, 5:04 PM
    #322 feat: Enhance provider states for pact-message Pull request opened by nsfrias • feat: allow multiple provider states to be defined in a pact • feat: allow additional parameters to be passed in the provider state Signed-off-by: Nuno Frias nsfrias@gmail.com pact-foundation/pact-python ✅ All checks have passed 5/5 successful checks
    • 1
    • 1
  • p

    Petr Šebek

    01/25/2023, 2:36 PM
    Hello, I have a question about enums in contract tests. My use-case is that I'd like to tests messages being sent in event-driven system (messaging) between publisher and subscriber. Imagine that I'm sending these enums as a part of message
    Copy code
    class TestEnumV1(str, Enum):
        OPTION_1 = "option_1"
        OPTION_2 = "option_2"
        OPTION_3 = "option_3"
    
    class TestEnumV2(str, Enum):
        OPTION_1 = "option_1"
        OPTION_2 = "option_2"
        OPTION_3 = "option_3"
        OPTION_4 = "option_4"
    Note that
    TestEnumV2
    has extra
    OPTION_4
    . I'm sending these messages as JSONs so it will be serialized as "option_4" string. Now
    TestEnumV1
    and
    TestEnumV2
    are not compatible because if publisher sends
    "option_4"
    to a subscriber understanding only
    TestEnumV1
    it will fail because subscriber will not know that value in
    TestEnumV1
    . However, if I write consumer matcher as
    pact.Like(TestEnumV1.OPTION_1)
    it will happily accept any string. I can write a regex for it
    pact.Term(r"^option_1|option_2|option_3$", "option_1")
    which would resolve it on consumer side. But what should I do on provider side? Should I generate and test message with every enum value possible? Is this (consumer and provider parts) how it should be done?
  • j

    Jayesh Guru

    01/25/2023, 3:15 PM
    Hey Folks I am getting below error while using EachLike in my expected response Body
    Copy code
    self = <pact.pact.Pact object at 0x7f5a847b4a90>
    
        def verify(self):
            """
            Have the mock service verify all interactions occurred.
    
            Calls the mock service to verify that all interactions occurred as
            expected, and has it write out the contracts to disk.
    
            :raises AssertionError: When not all interactions are found.
            """
            self._interactions = []
            resp = requests.get(
                self.uri + "/interactions/verification", headers=self.HEADERS, verify=False
            )
            assert resp.status_code == 200, resp.text
            resp = <http://requests.post|requests.post>(self.uri + "/pact", headers=self.HEADERS, verify=False)
    >       assert resp.status_code == 200, resp.text
    E       AssertionError: {"message":"Error ocurred in mock service: Filelock::ExecTimeout - Didn't finish executing Filelock block within the timeout specified.","backtrace":["/pyenv/versions/3.8.10/envs/cmedia-adf-management-api/lib/python3.8/site-packages/pact/bin/pact/lib/vendor/ruby/2.2.0/gems/pact-support-1.17.0/lib/pact/reification.rb:31:in `from_term'","/pyenv/versions/3.8.10/envs/cmedia-adf-management-api/lib/python3.8/site-packages/pact/bin/pact/lib/vendor/ruby/2.2.0/gems/pact-support-1.17.0/lib/pact/array_like.rb:44:in `block in generate'","/pyenv/versions/3.8.10/envs/cmedia-adf-management-api/lib/python3.8/site-packages/pact/bin/pact/lib/vendor/ruby/2.2.0/gems/pact-support-1.17.0/lib/pact/array_like.rb:44:in `times'","/pyenv/versions/3.8.10/envs/cmedia-adf-management-api/lib/python3.8/site-packages/pact/bin/pact/lib/vendor/ruby/2.2.0/gems/pact-support-1.17.0/lib/pact/array_like.rb:44:in `each'","/pyenv/versions/3.8.10/envs/cmedia-adf-management-api/lib/python3.8/site-packages/pact/bin/pact/lib/vendor/ruby/2.2.0/gems/pact-support-1.17.0/lib/pact/array_like.rb:44:in `collect'","/pyenv/versions/3.8.10/envs/cmedia-adf-management-
    Truncated
    
    /pyenv/versions/cmedia-adf-management-api/lib/python3.8/site-packages/pact/pact.py:281: AssertionError
  • g

    GitHub

    01/26/2023, 4:12 PM
    #325 chore: /s/Pactflow/PactFlow Pull request opened by YOU54F pact-foundation/pact-python ✅ All checks have passed 9/9 successful checks
    • 1
    • 1
  • g

    GitHub

    01/27/2023, 12:30 PM
    2 new commits pushed to
    <https://github.com/pact-foundation/pact-python/tree/master|master>
    by YOU54F
    <https://github.com/pact-foundation/pact-python/commit/44cda33f6836bb9e9af1984e5a03f06b5f969904|44cda33f>
    - chore: /s/Pactflow/PactFlow
    <https://github.com/pact-foundation/pact-python/commit/9c1132ef8ada47aa2d0dd94eb5795d9309e14f03|9c1132ef>
    - Merge pull request #325 from pact-foundation/pactflow_camelcase pact-foundation/pact-python
  • i

    Ivan Mikhalka

    02/06/2023, 8:44 AM
    Hello, could someone provide some examples how to work with Graphql API via
    pact-python
    ?
    m
    • 2
    • 9
  • g

    GitHub

    02/07/2023, 11:00 AM
    #326 Add GraphQL support Issue created by ivanmikhalka Hello, I am interested in adding GraphQL support in Python implementation. How much effort it could take to implement? pact-foundation/pact-python
  • s

    Sathish Sundararajan

    02/13/2023, 9:21 PM
    Does pact-python support gRPC contract tests? Pact-go has created a separate branch for adding gRPC support. Looking to see if there is similar traction on pact-python. Appreciate your guidance on this
    m
    • 2
    • 4
  • n

    Nuno Frias

    02/15/2023, 1:21 PM
    Hi all, Any chance a new build release of pact-python could be made available please? The last one (1.6.0) is almost 6 months old and I have been installing directly from the repo which takes forever. BTW the reason I do this is because I need a change that was recently merged into master.
  • e

    Elliott Murray

    02/15/2023, 2:34 PM
    Sorry I forgot to do this after the last couple of merges. Will do at the weekend. IIRC a few larger changes so will probably be a minor bump
    👍 1
    n
    m
    y
    • 4
    • 6
  • g

    GitHub

    02/19/2023, 11:28 AM
    1 new commit pushed to
    <https://github.com/pact-foundation/pact-python/tree/master|master>
    by elliottmurray
    <https://github.com/pact-foundation/pact-python/commit/48b7f3705d927b558e5aa4a95f1a1f6aac332309|48b7f370>
    - chore: Releasing version 1.7.0 pact-foundation/pact-python
  • g

    GitHub

    02/19/2023, 11:42 AM
    Release - pact-python-1.7.0 New release published by elliottmurray Minor to incorporate a few misc changes dating 6 months What's Changed • [Snyk] Security upgrade wheel from 0.24.0 to 0.38.0 by @mefellows in #317 • fix: setup security issue by @elliottmurray in #318 • feat: Enhance provider states for pact-message by @nsfrias in #322 • chore: /s/Pactflow/PactFlow by @YOU54F in #325 New Contributors • @mefellows made their first contribution in #317 • @nsfrias made their first contribution in #322 Full Changelog: v1.6.0...v1.7.0 pact-foundation/pact-python
  • g

    GitHub

    02/19/2023, 11:42 AM
    Upload Python Package #34 / deploy Deployment review requested by elliottmurray reviewers: @matthewbalvanz-wf, @Matt (pactflow.io / pact-js / pact-go), @bethesque, @elliottmurray, @uglyog Upload Python Package waiting for review pact-foundation/pact-python
  • g

    GitHub

    02/19/2023, 11:51 AM
    Upload Python Package #34 Deployment review approved by elliottmurray deploy Upload Python Package pact-foundation/pact-python
  • g

    GitHub

    02/19/2023, 11:51 AM
    Deployment to Upload Python Package by elliottmurray pact-foundation/pact-python
  • g

    GitHub

    02/19/2023, 12:01 PM
    #327 docs/updateReleaseDocs Pull request opened by elliottmurray pact-foundation/pact-python GitHub Actions: build (3.10) ✅ 8 other checks have passed 8/9 successful checks
    🎉 1
  • g

    GitHub

    02/20/2023, 9:52 AM
    #323 Allow multiple provider states and additional state parameters for Message Pact Issue created by nsfrias Currently for Message Pacts it is only possible to define a single provider state as a string. Check the method that sets the state: pact-python/pact/message_pact.py Lines 101 to 117 in </pact-foundation/pact-python/commit/d87d54bce2ed2f74b0a2bb46314b18541bdb598a|d87d54b> But often enough there is the need to define multiple provider states and also to be able to pass additional arguments to set the state (besides the provider state name). To this end I put together this pull request: #322 This change allows multiple providers states to be defined and also additional parameters to be passed for each state, for example:
    Copy code
    (
                target
                .given('there is an alligator named John',
                    params={'color':'green', 'weight_kg': 130, 'lenght_m': 1.95}
                )
                .given('there is an spider named Jack',
                    params={'color':'mostly black', 'weight_kg': 0.009, 'lenght_m': 0.05}
                )
                .expects_to_receive('an alligator message')
                .with_content({'name': 'John', 'document_name': 'sample_document.doc'})
                .with_metadata({'contentType': 'application/json',
                                'source': 'legacy_api',
                                'some-header': Term('\\d+-\\d+-\\d+T\\d+:\\d+:\\d+', '2022-02-15T20:16:01')})
            )
    It is also backwards compatible, in that it is possible to just pass a single state name. pact-foundation/pact-python
    • 1
    • 1
  • s

    Steve Wilkinson

    02/20/2023, 12:00 PM
    Hi all, I want to use
    pact-python
    to verify messages between a consumer and provider on an AWS SQS queue. What's the best way of using matchers in the consumer test? The problem is that if my expected message has matchers in it, my system under test can't parse the message as it doesn't understand the matchers. My workaround is to pass the message into the SUT as a serialized JSON string, using a custom serializer that converts the matcher objects into actual values. I'm new to Pact and I suspect I'm doing something wrong, is there a better way of doing this? Example expected message:
    Copy code
    expected_msg = {
        "timestamp": Term(
            matcher=Format.Regexes.timestamp.value,
            generate=datetime.datetime.now().strftime("%Y-%m-%dT%H:%M:%SZ"),
        ),
        "cat": {
            "name": "Saffy",
            "breed": "DomesticShorthair",
        },
    }
    n
    • 2
    • 4
  • s

    Steve Wilkinson

    02/21/2023, 2:11 PM
    Hi everyone, I'm using pact-python version 1.7.0. I've run into a problem when trying to publish a pact from my consumer test. It works if I pass a semantic version as the version number, but fails if I use a git commit hash. I'm getting this error:
    Copy code
    Received request message: {"resource": "cats", "method": "POST", "timeReceived": "2023-02-21T13:39:16Z", "cat": {"name": "Saffy", "breed": "DomesticShorthair"}}
    resource = cats, method = POST, time_received = 2023-02-21 13:39:16+00:00, cat = name='Saffy' breed=<CatBreed.DOMESTIC_SHORTHAIR: 'DomesticShorthair'>
    ----------------------------------------------------------------------- Captured stderr call -----------------------------------------------------------------------
    /home/swilkinson/repos/pact-poc-consumer-catsdb/.venv/lib/python3.9/site-packages/pact/bin/pact/lib/ruby/lib/ruby/gems/2.2.0/gems/bundler-1.9.9/lib/bundler/shared_helpers.rb:78: warning: Insecure world writable dir /mnt/c in PATH, mode 040777
    /home/swilkinson/repos/pact-poc-consumer-catsdb/.venv/lib/python3.9/site-packages/pact/bin/pact/lib/ruby/lib/ruby/2.2.0/rubygems/version.rb:206:in `initialize': Malformed version number string d3ba3948430b8a34ca5def0991648290010bf021 (ArgumentError)
            from /home/swilkinson/repos/pact-poc-consumer-catsdb/.venv/lib/python3.9/site-packages/pact/bin/pact/lib/ruby/lib/ruby/2.2.0/rubygems/version.rb:196:in `new'
            from /home/swilkinson/repos/pact-poc-consumer-catsdb/.venv/lib/python3.9/site-packages/pact/bin/pact/lib/ruby/lib/ruby/2.2.0/rubygems/version.rb:196:in `new'
            from /home/swilkinson/repos/pact-poc-consumer-catsdb/.venv/lib/python3.9/site-packages/pact/bin/pact/lib/vendor/ruby/2.2.0/gems/pact-message-0.11.1/lib/pact/message/cli.rb:26:in `update'
            from /home/swilkinson/repos/pact-poc-consumer-catsdb/.venv/lib/python3.9/site-packages/pact/bin/pact/lib/vendor/ruby/2.2.0/gems/thor-1.2.1/lib/thor/command.rb:27:in `run'
            from /home/swilkinson/repos/pact-poc-consumer-catsdb/.venv/lib/python3.9/site-packages/pact/bin/pact/lib/vendor/ruby/2.2.0/gems/thor-1.2.1/lib/thor/invocation.rb:127:in `invoke_command'
            from /home/swilkinson/repos/pact-poc-consumer-catsdb/.venv/lib/python3.9/site-packages/pact/bin/pact/lib/vendor/ruby/2.2.0/gems/thor-1.2.1/lib/thor.rb:392:in `dispatch'
            from /home/swilkinson/repos/pact-poc-consumer-catsdb/.venv/lib/python3.9/site-packages/pact/bin/pact/lib/vendor/ruby/2.2.0/gems/thor-1.2.1/lib/thor/base.rb:485:in `start'
            from /home/swilkinson/repos/pact-poc-consumer-catsdb/.venv/lib/python3.9/site-packages/pact/bin/pact/lib/app/pact-message.rb:28:in `<main>'
    /home/swilkinson/repos/pact-poc-consumer-catsdb/.venv/lib/python3.9/site-packages/pact/bin/pact/lib/ruby/lib/ruby/gems/2.2.0/gems/bundler-1.9.9/lib/bundler/shared_helpers.rb:78: warning: Insecure world writable dir /mnt/c in PATH, mode 040777
    No value provided for required pact_files
    Is it trying to validate the version number as a semantic version? If so is there a way to turn this off? This is the code I use to initialize the message consumer pact object:
    Copy code
    @pytest.fixture(scope="session")
    def consumer_pact(request):
        version = request.config.getoption("--publish-pact", None)
        publish = True if version else False
        branch = request.config.getoption("--branch-name", None)
    
        pact: MessagePact = MessageConsumer(CONSUMER_NAME, branch=branch).has_pact_with(
            provider=Provider(PROVIDER_NAME),
            publish_to_broker=publish,
            broker_base_url=PACT_BROKER_BASE,
            broker_token=PACT_BROKER_TOKEN,
            pact_dir=PACT_DIR,
            version=version,
        )
        yield pact
    👋 1
    y
    • 2
    • 5
  • s

    Slackbot

    02/21/2023, 2:11 PM
    https://docs.pact.io/getting_started/how_pact_works#how-to-write-message-pact-tests
  • g

    Gazal Gafoor

    03/01/2023, 1:30 PM
    @Gazal Gafoor has left the channel
  • g

    GitHub

    03/02/2023, 8:08 AM
    #328 doc: actualise guide on how to make contributions Pull request opened by sergeyklay Hi, It's is an attempt to update information on how to make contributions. This patch makes the following changes: • Replace the reference to the
    e2e
    directory with
    examples
    . The
    e2e
    directory has been deleted here #144 • Reformatted the file a bit to get rid of the horizontal scrolling • Removed mention of Travis, which apparently has not been used by project for a very long time • Replaced the broken links to the guides with others that will probably last longer • Updated the Python versions of the pyenv examples pact-foundation/pact-python ✅ All checks have passed 5/5 successful checks
    s
    m
    e
    • 4
    • 6
  • s

    Steve Wilkinson

    03/03/2023, 5:38 PM
    Hi folks, I'm trying to use the
    pact_url
    kwarg in my call to
    MessageProvider.verify_with_broker
    in order to verify against a specific pact, but it seems to be ignored. I always get this error: "pact.verify_wrapper.PactException: Pact urls or Pact broker required". What's the correct way to verify against a specific pact using pact-python?
    s
    • 2
    • 2
  • g

    GitHub

    03/05/2023, 12:46 AM
    #329 fix: replace yanked version of wheel with a more recent one Pull request opened by sergeyklay Reason for being yanked: Circular dependency with setuptools on --no-binary=all pact-foundation/pact-python GitHub Actions: build (3.10) ✅ 4 other checks have passed 4/5 successful checks
    s
    • 2
    • 2
  • g

    GitHub

    03/05/2023, 1:06 AM
    #330 fix: remove dead code Pull request opened by sergeyklay •
    missing_files
    was set twice, the second time is not used •
    provider_app_version
    was set twice with the same value • removed unnecessary brackets • fix link for GitHub badge pact-foundation/pact-python ✅ All checks have passed 7/7 successful checks
    s
    • 2
    • 2
  • g

    GitHub

    03/05/2023, 8:20 AM
    #331 ci: add python 3.11 to test matrix Pull request opened by sergeyklay • add python 3.11 to test matrix and setup.py • describe classifiers and python version for pypi package • replace yanked version of wheel with a more recent one • use compatible dependency versions for Python 3.6 closes #311 closes #329 pact-foundation/pact-python ✅ All checks have passed 7/7 successful checks
    s
    • 2
    • 2
1234567Latest