Skip to content

Commit 4ecf3f7

Browse files
authored
python: Add pytest and coverage (envoyproxy#15888)
- add separate tooling test job in ci - add pytest and a pytest runner - add coverage and cov runner - add pytests for all runners - upload coverage to https://storage.googleapis.com/envoy-pr/15888/tooling/index.html Signed-off-by: Ryan Northey <[email protected]>
1 parent 25b64a9 commit 4ecf3f7

23 files changed

+1212
-1
lines changed

.azure-pipelines/pipelines.yml

+22
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,28 @@ stages:
3333
# not all have fixes so improve condition/handling
3434
condition: failed()
3535

36+
- job: tooling
37+
dependsOn: []
38+
pool:
39+
vmImage: "ubuntu-18.04"
40+
steps:
41+
- script: ci/run_envoy_docker.sh 'ci/do_ci.sh tooling'
42+
workingDirectory: $(Build.SourcesDirectory)
43+
env:
44+
ENVOY_DOCKER_BUILD_DIR: $(Build.StagingDirectory)
45+
BAZEL_REMOTE_CACHE: grpcs://remotebuildexecution.googleapis.com
46+
BAZEL_REMOTE_INSTANCE: projects/envoy-ci/instances/default_instance
47+
GCP_SERVICE_ACCOUNT_KEY: $(GcpServiceAccountKey)
48+
displayName: "Run tooling checks"
49+
50+
- script: |
51+
ci/run_envoy_docker.sh 'ci/upload_gcs_artifact.sh /source/generated/tooling tooling'
52+
displayName: "Upload tooling coverage to GCS"
53+
env:
54+
ENVOY_DOCKER_BUILD_DIR: $(Build.StagingDirectory)
55+
GCP_SERVICE_ACCOUNT_KEY: $(GcpServiceAccountKey)
56+
GCS_ARTIFACT_BUCKET: $(GcsArtifactBucket)
57+
3658
- job: format
3759
dependsOn: ["format_pre"]
3860
pool:

.coveragerc

+11
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
[run]
2+
omit =
3+
tools/
4+
*/pytest_*.py
5+
6+
[report]
7+
exclude_lines =
8+
pragma: no cover
9+
raise NotImplementedError
10+
pass
11+
if __name__ == .__main__.:

.github/dependabot.yml

+5
Original file line numberDiff line numberDiff line change
@@ -70,3 +70,8 @@ updates:
7070
directory: "/configs"
7171
schedule:
7272
interval: "daily"
73+
74+
- package-ecosystem: "pip"
75+
directory: "/tools/testing"
76+
schedule:
77+
interval: "daily"

BUILD

+2
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,8 @@ exports_files([
44
"VERSION",
55
"API_VERSION",
66
".clang-format",
7+
"pytest.ini",
8+
".coveragerc",
79
])
810

911
# These two definitions exist to help reduce Envoy upstream core code depending on extensions.

bazel/repositories_extra.bzl

+12
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,13 @@ load("@proxy_wasm_cpp_host//bazel/cargo:crates.bzl", "proxy_wasm_cpp_host_fetch_
66
def _python_deps():
77
py_repositories()
88

9+
# REMOVE!!!
10+
pip_install(
11+
name = "sometools_pip3",
12+
requirements = "@envoy//tools/sometools:requirements.txt",
13+
extra_pip_args = ["--require-hashes"],
14+
)
15+
916
pip_install(
1017
name = "config_validation_pip3",
1118
requirements = "@envoy//tools/config_validation:requirements.txt",
@@ -88,6 +95,11 @@ def _python_deps():
8895
requirements = "@envoy//tools/code_format:requirements.txt",
8996
extra_pip_args = ["--require-hashes"],
9097
)
98+
pip_install(
99+
name = "testing_pip3",
100+
requirements = "@envoy//tools/testing:requirements.txt",
101+
extra_pip_args = ["--require-hashes"],
102+
)
91103
pip_install(
92104
name = "thrift_pip3",
93105
requirements = "@envoy//test/extensions/filters/network/thrift_proxy:requirements.txt",

ci/do_ci.sh

+8
Original file line numberDiff line numberDiff line change
@@ -466,6 +466,14 @@ elif [[ "$CI_TARGET" == "cve_scan" ]]; then
466466
bazel run "${BAZEL_BUILD_OPTIONS[@]}" //tools/dependency:cve_scan_test
467467
bazel run "${BAZEL_BUILD_OPTIONS[@]}" //tools/dependency:cve_scan
468468
exit 0
469+
elif [[ "$CI_TARGET" == "tooling" ]]; then
470+
echo "Run pytest tooling tests..."
471+
bazel run "${BAZEL_BUILD_OPTIONS[@]}" //tools/testing:pytest_python_pytest -- --cov-collect /tmp/.coverage-envoy
472+
bazel run "${BAZEL_BUILD_OPTIONS[@]}" //tools/testing:pytest_python_coverage -- --cov-collect /tmp/.coverage-envoy
473+
bazel run "${BAZEL_BUILD_OPTIONS[@]}" //tools/base:pytest_runner -- --cov-collect /tmp/.coverage-envoy
474+
bazel run "${BAZEL_BUILD_OPTIONS[@]}" //tools/base:pytest_utils -- --cov-collect /tmp/.coverage-envoy
475+
bazel run "${BAZEL_BUILD_OPTIONS[@]}" //tools/testing:python_coverage -- --fail-under=95 /tmp/.coverage-envoy /source/generated/tooling
476+
exit 0
469477
elif [[ "$CI_TARGET" == "verify_examples" ]]; then
470478
run_ci_verify "*" wasm-cc
471479
exit 0

pytest.ini

+4
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
[pytest]
2+
addopts = -raq --ignore=tools/testing/external/*,__init__.py,testing/conf --color=yes --cov-append -p tools.testing.plugin --cov-config=.coveragerc -vv tools
3+
testpaths =
4+
tests

0 commit comments

Comments
 (0)