{"library":"pytest-grpc","title":"pytest-grpc plugin","description":"pytest-grpc is a pytest plugin for testing gRPC services. It provides fixtures to start and stop gRPC servers and clients, allowing interaction with gRPC services during tests. The current stable version is 0.8.0, with releases occurring as new features are added or significant bugs are fixed, often following `pytest` or `grpcio` releases.","language":"python","status":"active","last_verified":"Mon May 18","install":{"commands":["pip install pytest-grpc"],"cli":null},"imports":["def test_example(grpc_channel): ...","def test_example(grpc_stub): ...","def test_example(grpc_server_factory): ...","import your_service_pb2_grpc\n@pytest.fixture(scope='session')\ndef grpc_add_to_server():\n    return your_service_pb2_grpc.add_YourServiceServicer_to_server","import pytest\nclass MyServicer(YourServiceServicer):\n    ...\n@pytest.fixture(scope='session')\ndef grpc_servicer():\n    return MyServicer()"],"auth":{"required":false,"env_vars":[]},"quickstart":{"code":"# conftest.py\nimport pytest\nimport grpc\n\n# Assuming you have compiled your_service.proto into your_service_pb2.py and your_service_pb2_grpc.py\n# e.g., using 'python -m grpc_tools.protoc -I. --python_out=. --grpc_python_out=. your_service.proto'\nimport your_service_pb2_grpc\nfrom your_service_pb2 import HelloRequest, HelloReply\n\n# Define your gRPC Servicer implementation\nclass MyTestServicer(your_service_pb2_grpc.GreeterServicer):\n    def SayHello(self, request, context):\n        return HelloReply(message=f\"Hello, {request.name} from test!\")\n\n# Provide the servicer instance\n@pytest.fixture(scope='session')\ndef grpc_servicer():\n    return MyTestServicer()\n\n# Provide the 'add_to_server' function from your generated _grpc module\n@pytest.fixture(scope='session')\ndef grpc_add_to_server():\n    return your_service_pb2_grpc.add_GreeterServicer_to_server\n\n# test_service.py\nimport your_service_pb2\n\ndef test_say_hello(grpc_stub):\n    # grpc_stub is an automatically created stub for your service\n    request = your_service_pb2.HelloRequest(name=\"World\")\n    response = grpc_stub.SayHello(request)\n    assert response.message == \"Hello, World from test!\"\n\ndef test_say_hello_with_channel(grpc_channel):\n    # You can also create a stub manually if needed\n    stub = your_service_pb2_grpc.GreeterStub(grpc_channel)\n    request = your_service_pb2.HelloRequest(name=\"ChannelUser\")\n    response = stub.SayHello(request)\n    assert response.message == \"Hello, ChannelUser from test!\"\n","lang":"python","description":"This quickstart demonstrates how to set up `pytest-grpc` using `conftest.py` to provide a test servicer and its `add_to_server` function. It then shows how to write a basic test using the `grpc_stub` fixture, which automatically handles server setup and client stub creation, or using `grpc_channel` to create a stub manually. This setup assumes you have generated Python gRPC code from your `.proto` definitions.","tag":null,"tag_description":null,"last_tested":null,"results":[]},"compatibility":{"tag":null,"tag_description":null,"last_tested":"2026-05-18","installed_version":"0.8.0","pypi_latest":"0.8.0","is_stale":false,"summary":{"python_range":"3.10–3.9","success_rate":100,"avg_install_s":2.7,"avg_import_s":null,"wheel_type":"wheel"},"results":[{"runtime":"python:3.10-alpine","python_version":"3.10","os_libc":"alpine (musl)","variant":"pytest-grpc","exit_code":0,"wheel_type":"wheel","failure_reason":null,"import_side_effects":"clean","install_time_s":null,"import_time_s":null,"mem_mb":null,"disk_size":"30.7M"},{"runtime":"python:3.10-slim","python_version":"3.10","os_libc":"slim (glibc)","variant":"pytest-grpc","exit_code":0,"wheel_type":"wheel","failure_reason":null,"import_side_effects":"clean","install_time_s":2.7,"import_time_s":null,"mem_mb":null,"disk_size":"31M"},{"runtime":"python:3.11-alpine","python_version":"3.11","os_libc":"alpine (musl)","variant":"pytest-grpc","exit_code":0,"wheel_type":"wheel","failure_reason":null,"import_side_effects":"clean","install_time_s":null,"import_time_s":null,"mem_mb":null,"disk_size":"33.6M"},{"runtime":"python:3.11-slim","python_version":"3.11","os_libc":"slim (glibc)","variant":"pytest-grpc","exit_code":0,"wheel_type":"wheel","failure_reason":null,"import_side_effects":"clean","install_time_s":2.6,"import_time_s":null,"mem_mb":null,"disk_size":"34M"},{"runtime":"python:3.12-alpine","python_version":"3.12","os_libc":"alpine (musl)","variant":"pytest-grpc","exit_code":0,"wheel_type":"wheel","failure_reason":null,"import_side_effects":"clean","install_time_s":null,"import_time_s":null,"mem_mb":null,"disk_size":"25.2M"},{"runtime":"python:3.12-slim","python_version":"3.12","os_libc":"slim (glibc)","variant":"pytest-grpc","exit_code":0,"wheel_type":"wheel","failure_reason":null,"import_side_effects":"clean","install_time_s":2.5,"import_time_s":null,"mem_mb":null,"disk_size":"26M"},{"runtime":"python:3.13-alpine","python_version":"3.13","os_libc":"alpine (musl)","variant":"pytest-grpc","exit_code":0,"wheel_type":"wheel","failure_reason":null,"import_side_effects":"clean","install_time_s":null,"import_time_s":null,"mem_mb":null,"disk_size":"25.0M"},{"runtime":"python:3.13-slim","python_version":"3.13","os_libc":"slim (glibc)","variant":"pytest-grpc","exit_code":0,"wheel_type":"wheel","failure_reason":null,"import_side_effects":"clean","install_time_s":2.6,"import_time_s":null,"mem_mb":null,"disk_size":"25M"},{"runtime":"python:3.9-alpine","python_version":"3.9","os_libc":"alpine (musl)","variant":"pytest-grpc","exit_code":0,"wheel_type":"wheel","failure_reason":null,"import_side_effects":"clean","install_time_s":null,"import_time_s":null,"mem_mb":null,"disk_size":"30.0M"},{"runtime":"python:3.9-slim","python_version":"3.9","os_libc":"slim (glibc)","variant":"pytest-grpc","exit_code":0,"wheel_type":"wheel","failure_reason":null,"import_side_effects":"clean","install_time_s":3.2,"import_time_s":null,"mem_mb":null,"disk_size":"30M"}]}}