Skip to content

Commit

Permalink
chore(ci): add coverage code for python (#7681)
Browse files Browse the repository at this point in the history
  • Loading branch information
anshbansal authored Mar 24, 2023
1 parent 918718e commit 1324231
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 4 deletions.
11 changes: 11 additions & 0 deletions .github/workflows/metadata-ingestion.yml
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,17 @@ jobs:
**/build/reports/tests/test/**
**/build/test-results/test/**
**/junit.*.xml
- name: Upload coverage to Codecov
if: ${{ always() && matrix.python-version == '3.10' && matrix.command != 'lint' }}
uses: codecov/codecov-action@v3
with:
token: ${{ secrets.CODECOV_TOKEN }}
directory: .
fail_ci_if_error: false
flags: pytest-${{ matrix.command }}
name: pytest-${{ matrix.command }}
verbose: true


event-file:
runs-on: ubuntu-latest
Expand Down
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -78,4 +78,5 @@ datahub-frontend/public/**
metadata-service/plugin/src/test/resources/sample-plugins/**

smoke-test/rollback-reports
coverage*.xml
.vercel
16 changes: 12 additions & 4 deletions metadata-ingestion/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,10 @@ if (!project.hasProperty("extra_pip_requirements")) {
ext.extra_pip_requirements = ""
}

def get_coverage_arg(test_name) {
return "--cov-report term --cov-report xml:coverage_${test_name}.xml "
}

task checkPythonVersion(type: Exec) {
commandLine python_executable, '-c',
'import sys; assert (3, 11) > sys.version_info >= (3, 7), f"Python version {sys.version_info[:2]} not allowed"'
Expand Down Expand Up @@ -121,8 +125,9 @@ task testQuick(type: Exec, dependsOn: [installDev, ':metadata-models:generateJso
inputs.files(project.fileTree(dir: "src/", include: "**/*.py"))
inputs.files(project.fileTree(dir: "tests/"))
outputs.dir("${venv_name}")
def cvg_arg = get_coverage_arg("quick")
commandLine 'bash', '-c',
"source ${venv_name}/bin/activate && pytest --durations=20 -m 'not integration and not integration_batch_1 and not slow_integration' -vv --continue-on-collection-errors --junit-xml=junit.quick.xml"
"source ${venv_name}/bin/activate && pytest ${cvg_arg} --durations=20 -m 'not integration and not integration_batch_1 and not slow_integration' -vv --continue-on-collection-errors --junit-xml=junit.quick.xml"
}

task installDevTest(type: Exec, dependsOn: [install]) {
Expand All @@ -149,13 +154,15 @@ task testSingle(dependsOn: [installDevTest]) {
}

task testIntegration(type: Exec, dependsOn: [installDevTest]) {
def cvg_arg = get_coverage_arg("int")
commandLine 'bash', '-c',
"source ${venv_name}/bin/activate && pytest --durations=50 -m 'integration' -vv --continue-on-collection-errors --junit-xml=junit.integration.xml"
"source ${venv_name}/bin/activate && pytest ${cvg_arg} --durations=50 -m 'integration' -vv --continue-on-collection-errors --junit-xml=junit.integration.xml"
}

task testIntegrationBatch1(type: Exec, dependsOn: [installDevTest]) {
def cvg_arg = get_coverage_arg("intBatch1")
commandLine 'bash', '-c',
"source ${venv_name}/bin/activate && pytest --durations=50 -m 'integration_batch_1' -vv --continue-on-collection-errors --junit-xml=junit.integrationbatch1.xml"
"source ${venv_name}/bin/activate && pytest ${cvg_arg} --durations=50 -m 'integration_batch_1' -vv --continue-on-collection-errors --junit-xml=junit.integrationbatch1.xml"
}

task testFull(type: Exec, dependsOn: [installDevTest]) {
Expand All @@ -164,8 +171,9 @@ task testFull(type: Exec, dependsOn: [installDevTest]) {
}

task testSlowIntegration(type: Exec, dependsOn: [installDevTest]) {
def cvg_arg = get_coverage_arg("intSlow")
commandLine 'bash', '-c',
"source ${venv_name}/bin/activate && pytest --durations=20 -m 'slow_integration' -vv --continue-on-collection-errors --junit-xml=junit.slow.integration.xml"
"source ${venv_name}/bin/activate && pytest ${cvg_arg} --durations=20 -m 'slow_integration' -vv --continue-on-collection-errors --junit-xml=junit.slow.integration.xml"
}

task docGen(type: Exec, dependsOn: [codegen, installDevTest]) {
Expand Down

0 comments on commit 1324231

Please sign in to comment.