Skip to content

Commit

Permalink
chore(ingest): refactor common pytest args (datahub-project#12240)
Browse files Browse the repository at this point in the history
  • Loading branch information
hsheth2 authored and chakru-r committed Jan 11, 2025
1 parent 8e2e030 commit 2a40fa3
Showing 1 changed file with 9 additions and 6 deletions.
15 changes: 9 additions & 6 deletions metadata-ingestion/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -127,6 +127,9 @@ task lintFix(type: Exec, dependsOn: installDev) {
"mypy --show-traceback --show-error-codes src/ tests/ examples/"
}

def pytest_default_env = "PYTHONDEVMODE=1"
def pytest_default_args = "--durations=30 -vv --continue-on-collection-errors"

task testQuick(type: Exec, dependsOn: [installDev, ':metadata-models:generateJsonSchema']) {
// We can't enforce the coverage requirements if we run a subset of the tests.
inputs.files(project.fileTree(dir: "src/", include: "**/*.py"))
Expand All @@ -135,7 +138,7 @@ task testQuick(type: Exec, dependsOn: [installDev, ':metadata-models:generateJso
def cvg_arg = get_coverage_args("quick")
commandLine 'bash', '-c',
"source ${venv_name}/bin/activate && set -x && " +
"pytest ${cvg_arg} tests/unit --random-order --durations=20 -m 'not integration' -vv --continue-on-collection-errors --junit-xml=junit.quick.xml"
"${pytest_default_env} pytest ${cvg_arg} tests/unit ${pytest_default_args} --random-order -m 'not integration' --junit-xml=junit.quick.xml"
}

task installDevTest(type: Exec, dependsOn: [install]) {
Expand All @@ -155,7 +158,7 @@ task testSingle(dependsOn: [installDevTest]) {
if (testFile != 'unknown') {
exec {
commandLine 'bash', '-c',
"source ${venv_name}/bin/activate && pytest ${testFile}"
"source ${venv_name}/bin/activate && ${pytest_default_env} pytest ${testFile} ${pytest_default_args}"
}
} else {
throw new GradleException("No file provided. Use -PtestFile=<test_file>")
Expand All @@ -167,25 +170,25 @@ task testIntegrationBatch0(type: Exec, dependsOn: [installDevTest]) {
def cvg_arg = get_coverage_args("intBatch0")
commandLine 'bash', '-c',
"source ${venv_name}/bin/activate && set -x && " +
"pytest ${cvg_arg} --durations=50 -m 'integration_batch_0' -vv --continue-on-collection-errors --junit-xml=junit.integrationbatch0.xml"
"${pytest_default_env} pytest ${cvg_arg} ${pytest_default_args} -m 'integration_batch_0' --junit-xml=junit.integrationbatch0.xml"
}
task testIntegrationBatch1(type: Exec, dependsOn: [installDevTest]) {
def cvg_arg = get_coverage_args("intBatch1")
commandLine 'bash', '-c',
"source ${venv_name}/bin/activate && set -x && " +
"pytest ${cvg_arg} --durations=50 -m 'integration_batch_1' -vv --continue-on-collection-errors --junit-xml=junit.integrationbatch1.xml"
"${pytest_default_env} pytest ${cvg_arg} ${pytest_default_args} -m 'integration_batch_1' --junit-xml=junit.integrationbatch1.xml"
}
task testIntegrationBatch2(type: Exec, dependsOn: [installDevTest]) {
def cvg_arg = get_coverage_args("intBatch2")
commandLine 'bash', '-c',
"source ${venv_name}/bin/activate && set -x && " +
"pytest ${cvg_arg} --durations=20 -m 'integration_batch_2' -vv --continue-on-collection-errors --junit-xml=junit.integrationbatch2.xml"
"${pytest_default_env} pytest ${cvg_arg} ${pytest_default_args} -m 'integration_batch_2' --junit-xml=junit.integrationbatch2.xml"
}

task testFull(type: Exec, dependsOn: [installDevTest]) {
commandLine 'bash', '-c',
"source ${venv_name}/bin/activate && set -x && " +
"pytest --durations=50 -vv --continue-on-collection-errors --junit-xml=junit.full.xml"
"${pytest_default_env} pytest ${pytest_default_args} --junit-xml=junit.full.xml"
}

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

0 comments on commit 2a40fa3

Please sign in to comment.