Reddit
reddit.com › r/python › useful libraries for integration/api testing
r/Python on Reddit: Useful libraries for integration/api testing
February 21, 2023 -
I'd like to enhance my integration/api testing, looking for useful libraries that do all sort of stuff like asserting on HTTP responses, mocking network requests, verifying OpenAPI or anything similar that can improve my DX. Appreciate your ideas
Top answer 1 of 3
5
asserting on HTTP responses If you dont want to use the built in assertions, there are modules like pyresttest and pyhttptest. Honestly using assertions with requests is going to be easier. I guess you are looking for something like RestAssured from Java but for Python. Python doesn't really embrace the same kind of API style that Java does, so you probably wont find many things like that in this space. You can always use stuff like json path libraries and xpath libraries on pypi to deal with body assertions if you want to use that. mocking Assuming you mean mocking external services rather than object mocking as that is generally aimed at unit testing. If you need to mock network requests at an integration level, I'd probably suggest using tooling such as testcontainers. That lets you spin up a container within Docker for whatever you want (it supports Kafka, Mockserver (HTTP), localstack (full AWS API) etc out of the box). You can also then make use of WireMock and the Python WireMock Admin API if you want something more involved (again, using test containers). Testcontainers will also let you run databases and other stuff programmatically too. Verifying OpenAPI That isn't really Python specific, and is not possible to fully automate from a black box perspective (since you cant really just infer what operations and payloads and headers are needed in a standard way from just observing a running REST API). You could avoid this by using something like APIFlask for Flask, or drf-spectacular for Django to create your OA3 specs from your code at runtime instead though. From an API level, you could alternatively consider using a transport like gRPC rather than a pure REST API, or use protobuf for your serialization format. That would enable you to write your payloads in protobuf files and distribute them to the end users so they can recreate the API clients/payloads on their side directly via protoc. That would reduce the need for such heavy documentation using OpenAPI 3 as you'd then be mostly just documenting the parameters on the generated code like any other library API. Ideas If you are doing acceptance testing, I'd probably suggest using behavioural-driven-development using a tool like behave rather than using pytest or unittest or nose directly. That way you can keep your test logic in readable feature requirements files. https://behave.readthedocs.io/en/stable/tutorial.html https://cucumber.io/ Pytest has a BDD plugin but last time I used it, it was overly clunky and awkward in comparison to behave. It felt like it didnt really capture the spirit of BDD features being more agnostic since there were a bunch of fairly common requirements that it didnt really fulfill for me. If you need something like awaitility in Java and do not want to just write a basic shim around threads or asyncio, there is this library too: https://pypi.org/project/busypie/ I leave with an unpopular opinion here: a lot of the testing frameworks in Python do not feel as developed as other languages which is unfortunate. For example, Java has full support for Cucumber rather than using a separately maintained API. Testcontainers is far more robust and customizable (esp. with respect to Kafka), higher level libraries like JooQ exist for expressing stuff like SQL with a DSL without needing to delegate to an ORM and hope that the ORM supports all the features of SQL that you need. You also have tools like awaitility, first class support for Wiremock and Mockserver, proper in memory databases for testing like H2 and Derby. Stuff like Restassured also exists. You also have tools like Skyscreamer JSON Assert, XML Assert, etc. Python does seem to lack in this regard, so you will likely find yourself having to write some common code in a library eventually to achieve some more bespoke common stuff you may need to do in tests. (Disclaimer, I work writing cloud Java and Python APIs and systems; I cant speak as well for other langs like C#, Ruby, PHP, Rust, Go, etc).
2 of 3
1
Pytest
Pylonsproject
docs.pylonsproject.org › projects › pyramid › en › latest › narr › testing.html
Unit, Integration, and Functional Testing — The Pyramid Web Framework v2.1
In the context of a Pyramid integration test, the test logic exercises the functionality of the code under test and its integration with the rest of the Pyramid framework.
testing - Integration test in python - Stack Overflow
I have a python project that I want to test. I already have unit test with unittest but I need to do integration tests. For that, I have two applications: the real one that I have to test, and a " More on stackoverflow.com
Options for automated testing framework (not unittest)
All the frameworks I have seen (unittest, pytest etc) all concentrate on unit tests, calling class methods with a bunch of asserts in them. I dont think this kind of testing suits me. I need to do stuff like re-run certain tests multiple times with different data (and expect different outputs). all of the frameworks that you mentioned can do "re-run certain tests multiple times with different data (and expect different outputs)." More on reddit.com
Best testing framework?
You can't go wrong with Pytest – it's what almost everyone uses (or at least knows), and it's not hard to get into. Another option would be Hypothesis if you're feeling more adventurous. I haven't tried it myself but it sure seems like an interesting approach. More on reddit.com
Python unit test resources...
Anything by Brian Okken. He has a podcast called Test and Code, is on Python Bytes, and has written a few books on writing tests with pytest. He also maintains a bunch of useful pytest libraries. More on reddit.com
Videos
37:24
PyTest • REST API Integration Testing with Python - YouTube
54:15
Testing Your Python Code Base: Unit vs. Integration | Real Python ...
00:31
Unit vs Integration vs End-to-End Testing in Python - YouTube
Why Integration Tests Might Be All You Need
22:57
How to Write Great Unit Tests in Python - YouTube
01:31:29
Python Web Apps: Testing with Pytest and Playwright - YouTube
DEV Community
dev.to › amnish04 › testing-in-python-4ne7
Testing in Python - DEV Community
November 15, 2023 - To begin with, I added a very general test that called my program against a markdown file, and comparted the generated html with the expected snapshot. I created a dictionary to store the expected snapshots in a separate file. ... """Html snapshots to be used in integration testing""" snapshots = { "yattag_html": """<!DOCTYPE html> <html lang="en-CA"> <head> <meta charset="utf-8" /> <title># TIL *Yattag*</title> <meta name="viewport" content="width=device-width, initial-scale=1" /> </head> <body> <h2>Table of Contents</h2> ...
Medium
medium.com › @ujwalabothe › integration-testing-with-pytest-testing-real-world-scenarios-c506f4bf1bff
Integration Testing with pytest: Testing Real-World Scenarios | by Ujwala Bothe | Medium
November 16, 2023 - By subjecting the software to real-world scenarios and usage patterns, integration testing can reveal complex bugs and errors that may arise only when multiple components interact. It helps identify issues such as data corruption, communication failures, and improper resource handling. Introducing pytest as a Popular Testing Framework: Python developers are well-acquainted with pytest, a widely used testing framework known for its simplicity and extensibility.
BrowserStack
browserstack.com › home › guide › top 15 python testing frameworks in 2025
Top 15 Python Testing Frameworks in 2025 | BrowserStack
November 13, 2025 - When you need to integrate tests with continuous delivery pipelines and validate business requirements at each stage of development. Radish is a behavior-driven development (BDD) framework for Python. It extends the Gherkin syntax used by frameworks like Behave and provides features such as scenario loops, background steps, and flexible step arguments.
Dian Apps
dianapps.com › home › python integration testing
Python Integration Testing
May 28, 2025 - Pytest is a lightweight Python testing framework. It’s an excellent framework for integration and unit testing in Python, with a very gentle learning curve in addition to being time-saving due to its capacity for headless parallel testing. Pytest offers a more streamlined and concise method of creating Python test cases.
Medium
medium.com › @KMSSolutions › ensuring-python-modules-together-python-integration-testing-strategies-a518065d1f1f
Ensuring Python Modules Together: Python Integration Testing Strategies | by KMS Solutions | Medium
November 5, 2024 - When conducting integration testing with Pytest, the framework yields human-readable test results that outline the test progress and pinpoint errors in the code. Python developers appreciate the convenience of executing test suites via the command line, favoring the straightforward process of running the Pytest command directly from the test folder terminal.
PyPI
pypi.org › project › pytest-integration
pytest-integration · PyPI
Framework · Pytest · License · OSI Approved :: MIT License · Operating System · OS Independent · Programming Language · Python :: 3 · Report project as malware · Plugin for pytest to mark tests as integration or slow integration.
» pip install pytest-integration
GitHub
github.com › cleder › awesome-python-testing
GitHub - cleder/awesome-python-testing: Collection of awesome 😎️ Python resources for testing
Mockafka - Python library designed for mocking Kafka in a testing environment. It simplifies testing Kafka-integrated applications by providing an in-memory mock for aiokafka and confluent-kafka-python. mocket - A socket mock framework with gevent/asyncio/SSL support.
Starred by 279 users
Forked by 36 users