Skip to content

keploy/python-sdk

contributions welcome Slack License

Note :- Issue Creation is disabled on this Repository, please visit here to submit issue.

Keploy Python-SDK

This is the client SDK for the Keploy testing platform. With the Python SDK, you can test both your existing unit test cases in Pytest and create new end-to-end test cases for your applications. The HTTP mocks/stubs and tests are the same format and inter-exchangeable.

Contents

  1. Installation
  2. Usage
  3. Community support

Installation

  1. First you need to install Python(version 3 and above)

  2. Install the Python-SDK and also Python's coverage library via pip.

pip install keploy coverage
  1. Install Keploy from here

Usage

Keploy simplifies the testing process by seamlessly generating end-to-end test cases without the need to write unit test files and manage mocks/stubs.

Add a test file with the following code to the directory with all your existing tests. This will help us to get the coverage of Keploy's API tests along with the other unit tests. We can call this test_keploy.py

from keploy import run
def test_keploy():
    run("python3 -m coverage run --data-file=.coverage_data.keploy <command-to-run-your-application>")

Note: If you face any problems with running the coverage library, you can refer to the documentation for the same here

To ignore the coverage of python libraries which are included in the report by default, you need to create a .coveragerc file in the directory where you will ignore the /usr/ directory(only for Linux users). The contents of the file will be as follows:

[run]
omit =
    /usr/*
sigterm = true

Before starting your application, make sure that the debug mode is set to False in your application, for the coverage library to work properly.

Now to run this testcase along with your another unit testcases, you can run the command below:

keploy test -c "python3 -m coverage run -p --data-file=.coverage.unit -m pytest test_keploy.py <your-unit-test-file>" --delay 10 --coverage

Now, to combine the coverage from the unit tests, and Keploy's API tests, we can use the command below:

python3 -m coverage combine

Make sure to run this command before starting a new test run to avoid getting multiple coverage files.

Finally, to generate the coverage report for the test run, you can run:

python3 -m coverage report

and if you want the coverage in an html file, you can run:

python3 -m coverage html

Hooray🎉! You've sucessfully got the coverage of your Keploy recorded api tests using Pytest.

Community support

We'd love to collaborate with you to make Keploy.io great. To get started:

  • Slack - Discussions with the community and the team.
  • GitHub - For bug reports and feature requests.