File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -21,6 +21,22 @@ For example to run the tests for Python 3.9:
2121tox -epy39
2222```
2323
24+ Generated BDD artifacts
25+ -----------------------
26+
27+ The OpenAPI transformer can generate a shared request-plan database, recording
28+ server, and copy of the feature corpus. After generating those artifacts into
29+ ` tests/generated ` , run them through the Python SDK's native pytest-bdd adapter:
30+
31+ ``` shell
32+ ./run-bdd-tests.sh
33+ ```
34+
35+ Set ` BDD_TEST_ARTIFACTS ` when the generated artifact directory is elsewhere.
36+ The adapter builds requests from the generated plans and points every SDK client,
37+ including setup and undo calls, at the generated recording server. The SDK does
38+ not need access to the spec repository or the transformer at test runtime.
39+
2440To pass extra arguments to run the tests, you need to close ` tox ` arguments with ` -- ` .
2541You can get more verbose information with the ` -v ` flag to ` pytest ` , filter the tests using the ` -k ` or
2642specifying the test full path. For example:
Original file line number Diff line number Diff line change 1+ #! /usr/bin/env bash
2+
3+ set -euo pipefail
4+
5+ REPO_ROOT=" $( cd -- " $( dirname " $0 " ) " > /dev/null 2>&1 && pwd -P) "
6+ TEST_ARTIFACTS=${BDD_TEST_ARTIFACTS:- ${REPO_ROOT} / tests/ generated}
7+
8+ if [ ! -x " ${TEST_ARTIFACTS} /test-server" ]; then
9+ echo " Generated test server not found at ${TEST_ARTIFACTS} /test-server" >&2
10+ exit 1
11+ fi
12+ if [ ! -f " ${TEST_ARTIFACTS} /test-runner-data/manifest.json" ]; then
13+ echo " Generated test runner manifest not found below ${TEST_ARTIFACTS} " >&2
14+ exit 1
15+ fi
16+
17+ TEST_SERVER_PID=" "
18+ cleanup () {
19+ if [ -n " ${TEST_SERVER_PID} " ]; then
20+ kill " ${TEST_SERVER_PID} " 2> /dev/null || true
21+ fi
22+ }
23+ trap cleanup EXIT
24+
25+ TEST_SERVER_PORT=${BDD_TEST_SERVER_PORT:- 18082}
26+ TEST_SERVER_LOG=${BDD_TEST_SERVER_LOG:- ${TMPDIR:-/ tmp} / datadog-python-test-server.log}
27+ " ${TEST_ARTIFACTS} /test-server" --port " ${TEST_SERVER_PORT} " > " ${TEST_SERVER_LOG} " 2>&1 &
28+ TEST_SERVER_PID=$!
29+ for _ in {1..50}; do
30+ if curl --silent --fail " http://127.0.0.1:${TEST_SERVER_PORT} /__openapi_transformer__/health" > /dev/null; then
31+ break
32+ fi
33+ sleep 0.1
34+ done
35+ curl --silent --fail " http://127.0.0.1:${TEST_SERVER_PORT} /__openapi_transformer__/health" > /dev/null
36+
37+ cd " ${REPO_ROOT} "
38+ TEST_MODULES=()
39+ for version in v1 v2; do
40+ if [ -d " ${TEST_ARTIFACTS} /test-runner-data/features/${version} " ]; then
41+ TEST_MODULES+=(" tests/${version} /test_scenarios.py" )
42+ fi
43+ done
44+ if [ " ${# TEST_MODULES[@]} " -eq 0 ]; then
45+ echo " No generated feature directories found below ${TEST_ARTIFACTS} /test-runner-data/features" >&2
46+ exit 1
47+ fi
48+
49+ DD_TEST_SERVER_URL=" http://127.0.0.1:${TEST_SERVER_PORT} " \
50+ DD_TEST_RUNNER_DATA=" ${TEST_ARTIFACTS} /test-runner-data" \
51+ RECORD=false \
52+ python -m pytest " ${TEST_MODULES[@]} " -q " $@ "
You can’t perform that action at this time.
0 commit comments