Skip to content

Conversation

@wanlin31
Copy link
Collaborator

@wanlin31 wanlin31 commented Aug 20, 2025

This CL add:

  • Added test-server wrapper for easy adoption for python tests.
  • Upon build the package, the hooked up install.py automatically download the golang executable and make it available for the wrapper to use.
  • Added sample test as manual e2e test for now to ensure the test-wrapper works as expected, can be added as a CI at a later time.

Test steps (from sdks/python):

python3 -m venv ~/env
source ~/env/bin/activate
pip3 install -r requirements.txt
rm -rf build/ dist/ *.egg-info/ src/test_server_sdk/bin/ && find . -depth -name "__pycache__" -type d -exec rm -rf {} \;
python3 -m build

cd sample
pip install --force-reinstall ../dist/test_server_sdk-0.1.0-py3-none-any.whl
pip show -f test_server_sdk
# run test with replay mode
pytest -sv

# run test with record mode
pytest -sv --record

Built information

pip show -f test_server_sdk
Name: test-server-sdk
Version: 0.1.0
Summary: A python wrapper for test-server.
Home-page: https://github.com/google/test-server/sdks/python
Author:
Author-email: Google LLC <googleapis-packages@google.com>
License-Expression: Apache-2.0
Location: /usr/local/google/home/wanlindu/env/lib/python3.13/site-packages
Requires: PyYAML, requests
Required-by:
Files:
  src/test_server_sdk/__init__.py
  src/test_server_sdk/__pycache__/__init__.cpython-313.pyc
  src/test_server_sdk/__pycache__/test_server_wrapper.cpython-313.pyc
  src/test_server_sdk/test_server_wrapper.py
  test_server_sdk-0.1.0.dist-info/INSTALLER
  test_server_sdk-0.1.0.dist-info/METADATA
  test_server_sdk-0.1.0.dist-info/RECORD
  test_server_sdk-0.1.0.dist-info/REQUESTED
  test_server_sdk-0.1.0.dist-info/WHEEL
  test_server_sdk-0.1.0.dist-info/direct_url.json
  test_server_sdk-0.1.0.dist-info/licenses/LICENSE
  test_server_sdk-0.1.0.dist-info/top_level.txt
  test_server_sdk/__init__.py
  test_server_sdk/__pycache__/__init__.cpython-313.pyc
  test_server_sdk/__pycache__/test_server_wrapper.cpython-313.pyc
  test_server_sdk/bin/CHANGELOG.md
  test_server_sdk/bin/LICENSE
  test_server_sdk/bin/README.md
  test_server_sdk/bin/test-server
  test_server_sdk/test_server_wrapper.py

Record mode.

platform linux -- Python 3.13.3, pytest-8.4.1, pluggy-1.6.0 -- /usr/local/google/home/wanlindu/env/bin/python3
cachedir: .pytest_cache
rootdir: /usr/local/google/home/wanlindu/test-server/sdks/python
configfile: pyproject.toml
plugins: anyio-4.10.0, parallel-0.1.1, cov-6.2.1, asyncio-1.1.0
asyncio: mode=Mode.STRICT, asyncio_default_fixture_loop_scope=None, asyncio_default_test_loop_scope=function
collected 2 items

test_sample.py::TestSampleWithServer::test_should_receive_200_from_proxied_github
[PyTest] Using test-server mode: 'record'
Starting test-server in 'record' mode...
   Command: /usr/local/google/home/wanlindu/env/lib/python3.13/site-packages/test_server_sdk/bin/test-server record --config /usr/local/google/home/wanlindu/test-server/sdks/python/sample/test-data/config/test-server-config.yml --recording-dir /usr/local/google/home/wanlindu/test-server/sdks/python/sample/test-data/recordings
Reading config file for health check endpoints: /usr/local/google/home/wanlindu/test-server/sdks/python/sample/test-data/config/test-server-config.yml
Performing health check on: http://localhost:17080/healthz
[test-server STDOUT] Recording to directory: /usr/local/google/home/wanlindu/test-server/sdks/python/sample/test-data/recordings
[test-server STDOUT] Starting server for {https github.com 443 17080 http /healthz [] []}
Health check for http://localhost:17080/healthz passed.
[PyTest] Test-server started with PID: 1632671
[PyTest] Making request to test-server proxy for www.github.com...
[test-server STDOUT] Recording request: GET /
[PyTest] Received 200 OK, content check passed.
PASSEDStopping test-server process (PID: 1632671)...
Server terminated gracefully.

test_sample.py::TestAnotherSampleWithoutServer::test_should_run_basic_check
[PyTest] Running a test that does not manage the test-server.
PASSED

Replay mode:

platform linux -- Python 3.13.3, pytest-8.4.1, pluggy-1.6.0 -- /usr/local/google/home/wanlindu/env/bin/python3
cachedir: .pytest_cache
rootdir: /usr/local/google/home/wanlindu/test-server/sdks/python
configfile: pyproject.toml
plugins: anyio-4.10.0, parallel-0.1.1, cov-6.2.1, asyncio-1.1.0
asyncio: mode=Mode.STRICT, asyncio_default_fixture_loop_scope=None, asyncio_default_test_loop_scope=function
collected 2 items

test_sample.py::TestSampleWithServer::test_should_receive_200_from_proxied_github
[PyTest] Using test-server mode: 'replay'
Starting test-server in 'replay' mode...
   Command: /usr/local/google/home/wanlindu/env/lib/python3.13/site-packages/test_server_sdk/bin/test-server replay --config /usr/local/google/home/wanlindu/test-server/sdks/python/sample/test-data/config/test-server-config.yml --recording-dir /usr/local/google/home/wanlindu/test-server/sdks/python/sample/test-data/recordings
Reading config file for health check endpoints: /usr/local/google/home/wanlindu/test-server/sdks/python/sample/test-data/config/test-server-config.yml
Performing health check on: http://localhost:17080/healthz
[test-server STDOUT] Replaying from directory: /usr/local/google/home/wanlindu/test-server/sdks/python/sample/test-data/recordings
Health check for http://localhost:17080/healthz passed.
[PyTest] Test-server started with PID: 1631021
[PyTest] Making request to test-server proxy for www.github.com...
[test-server STDOUT] Replaying request: GET / HTTP/1.1s
[test-server STDOUT] Replaying http request: GET / HTTP/1.1
[test-server STDOUT] loading response from : /usr/local/google/home/wanlindu/test-server/sdks/python/sample/test-data/recordings/396bab503f4b90ad88858bb4467d59b9e827dcd82e33f41c230e1b8fb43bdc8c.json with shaSum: 396bab503f4b90ad88858bb4467d59b9e827dcd82e33f41c230e1b8fb43bdc8c
[PyTest] Received 200 OK, content check passed.
PASSEDStopping test-server process (PID: 1631021)...
Server terminated gracefully.

test_sample.py::TestAnotherSampleWithoutServer::test_should_run_basic_check
[PyTest] Running a test that does not manage the test-server.
PASSED

@wanlin31 wanlin31 force-pushed the wrapper branch 2 times, most recently from 08ddc05 to 391a552 Compare August 23, 2025 00:26
@wanlin31 wanlin31 marked this pull request as ready for review August 23, 2025 00:26
@wanlin31 wanlin31 requested review from Annhiluc and hkt74 August 23, 2025 00:26
@wanlin31 wanlin31 force-pushed the wrapper branch 2 times, most recently from c29e356 to 14fba09 Compare August 25, 2025 23:11
@wanlin31 wanlin31 removed request for Annhiluc and hkt74 August 26, 2025 17:19
@wanlin31 wanlin31 force-pushed the wrapper branch 4 times, most recently from a68124d to 2622810 Compare August 26, 2025 23:08
@wanlin31 wanlin31 requested review from Annhiluc and hkt74 August 26, 2025 23:08
@wanlin31 wanlin31 requested review from Annhiluc and hkt74 August 28, 2025 16:34
@wanlin31 wanlin31 merged commit d26939a into google:main Aug 28, 2025
2 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants